<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using JavaScript variables in SearchManager in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Using-JavaScript-variables-in-SearchManager/m-p/709153#M58001</link>
    <description>&lt;P&gt;Take a look at this example, where it sets the search property outside the initial constructor&lt;/P&gt;&lt;P&gt;&lt;A href="https://dev.splunk.com/enterprise/docs/developapps/visualizedata/addsearches/searchproperties" target="_blank"&gt;https://dev.splunk.com/enterprise/docs/developapps/visualizedata/addsearches/searchproperties&lt;/A&gt;&lt;/P&gt;&lt;P&gt;i.e.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;        // Update the search query
        mysearch.settings.set("search", "index=_internal | head 2");&lt;/LI-CODE&gt;</description>
    <pubDate>Sun, 19 Jan 2025 02:06:59 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2025-01-19T02:06:59Z</dc:date>
    <item>
      <title>Using JavaScript variables in SearchManager</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Using-JavaScript-variables-in-SearchManager/m-p/709149#M58000</link>
      <description>&lt;P&gt;I am using SplunkJS to display an HTML page with JavaScript. I have tried everything to try and get the SearchManager query to use a JavaScript variable (ex. using splQuery, +splQuery+, etc.). If I enter the Splunk query in quotes instead of the variable, it does work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var splQuery = "| makeresults";
var SearchManager = require("splunkjs/mvc/searchmanager");

var mysearch = new SearchManager({
  id: "mysearch",
  autostart: "false",
  search: splQuery
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jan 2025 18:46:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Using-JavaScript-variables-in-SearchManager/m-p/709149#M58000</guid>
      <dc:creator>fratamicod</dc:creator>
      <dc:date>2025-01-18T18:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using JavaScript variables in SearchManager</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Using-JavaScript-variables-in-SearchManager/m-p/709153#M58001</link>
      <description>&lt;P&gt;Take a look at this example, where it sets the search property outside the initial constructor&lt;/P&gt;&lt;P&gt;&lt;A href="https://dev.splunk.com/enterprise/docs/developapps/visualizedata/addsearches/searchproperties" target="_blank"&gt;https://dev.splunk.com/enterprise/docs/developapps/visualizedata/addsearches/searchproperties&lt;/A&gt;&lt;/P&gt;&lt;P&gt;i.e.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;        // Update the search query
        mysearch.settings.set("search", "index=_internal | head 2");&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 19 Jan 2025 02:06:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Using-JavaScript-variables-in-SearchManager/m-p/709153#M58001</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2025-01-19T02:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using JavaScript variables in SearchManager</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Using-JavaScript-variables-in-SearchManager/m-p/709170#M58002</link>
      <description>&lt;P&gt;I just tried, but unfortunately this is not working. I'm still running into the same issue where the search is not using the JavaScript variable. In the below code, I even tried "+splQuery+" but nothing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var splQuery = "| makeresults";
var SearchManager = require("splunkjs/mvc/searchmanager");

var mysearch = new SearchManager({
  id: "mysearch",
  autostart: "false",
  search: ""
});

mysearch.settings.set("search", splQuery);​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2025 14:59:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Using-JavaScript-variables-in-SearchManager/m-p/709170#M58002</guid>
      <dc:creator>fratamicod</dc:creator>
      <dc:date>2025-01-19T14:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using JavaScript variables in SearchManager</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Using-JavaScript-variables-in-SearchManager/m-p/709174#M58003</link>
      <description>&lt;P&gt;This is an example from the Splunk dashboard examples app - (Custom Table Row Expansion) - which shows lazy search string evaluation.&lt;/P&gt;&lt;P&gt;&lt;A href="https://splunkbase.splunk.com/app/1603" target="_blank"&gt;https://splunkbase.splunk.com/app/1603&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;requirejs([
    '../app/simple_xml_examples/libs/underscore-1.6.0-umd-min',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/chartview',
    'splunkjs/mvc/searchmanager',
    'splunkjs/mvc',
    'splunkjs/mvc/simplexml/ready!'
], function(_, TableView, ChartView, SearchManager, mvc) {
    var EventSearchBasedRowExpansionRenderer = TableView.BaseRowExpansionRenderer.extend({
        initialize: function() {
            // initialize will run once, so we will set up a search and a chart to be reused.
            this._searchManager = new SearchManager({
                id: 'details-search-manager',
                preview: false
            });
            this._chartView = new ChartView({
                'managerid': 'details-search-manager',
                'charting.legend.placement': 'none'
            });
        },

        canRender: function(rowData) {
            // Since more than one row expansion renderer can be registered we let each decide if they can handle that
            // data
            // Here we will always handle it.
            return true;
        },

        render: function($container, rowData) {
            // rowData contains information about the row that is expanded.  We can see the cells, fields, and values
            // We will find the sourcetype cell to use its value
            var sourcetypeCell = _(rowData.cells).find(function (cell) {
                return cell.field === 'sourcetype';
            });

            //update the search with the sourcetype that we are interested in
            this._searchManager.set({ search: 'index=_internal sourcetype=' + sourcetypeCell.value + ' | timechart count' });

            // $container is the jquery object where we can put out content.
            // In this case we will render our chart and add it to the $container
            $container.append(this._chartView.render().el);
        }
    });

    var tableElement = mvc.Components.getInstance('expand_with_events');
    tableElement.getVisualization(function(tableView) {
        // Add custom cell renderer, the table will re-render automatically.
        tableView.addRowExpansionRenderer(new EventSearchBasedRowExpansionRenderer());
    });
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2025 21:10:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Using-JavaScript-variables-in-SearchManager/m-p/709174#M58003</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2025-01-19T21:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using JavaScript variables in SearchManager</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Using-JavaScript-variables-in-SearchManager/m-p/709319#M58010</link>
      <description>&lt;P&gt;Still not working for me, unfortunately.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 14:30:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Using-JavaScript-variables-in-SearchManager/m-p/709319#M58010</guid>
      <dc:creator>fratamicod</dc:creator>
      <dc:date>2025-01-21T14:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using JavaScript variables in SearchManager</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Using-JavaScript-variables-in-SearchManager/m-p/709511#M58015</link>
      <description>&lt;P&gt;I had to use a combination of plain text and a JavaScript variable for this to work.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var splQuery = "makeresults";
var SearchManager = require("splunkjs/mvc/searchmanager");

var mysearch = new SearchManager({
  id: "mysearch",
  autostart: "false",
  search: "| " + splQuery
});&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 22 Jan 2025 19:26:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Using-JavaScript-variables-in-SearchManager/m-p/709511#M58015</guid>
      <dc:creator>fratamicod</dc:creator>
      <dc:date>2025-01-22T19:26:17Z</dc:date>
    </item>
  </channel>
</rss>

