<?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: Self defined variable format in javascript search query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Self-defined-variable-format-in-javascript-search-query/m-p/311050#M164648</link>
    <description>&lt;P&gt;@clement, seems like you are using post processing to overcome the issue you were facing. While init section to initialize token is a different approach. But I am glad you found something working for you.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Dec 2017 08:08:14 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-12-04T08:08:14Z</dc:date>
    <item>
      <title>Self defined variable format in javascript search query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Self-defined-variable-format-in-javascript-search-query/m-p/311045#M164643</link>
      <description>&lt;P&gt;I found many token based variable search examples online but not on own created variable in customized Javascript. E.g: &lt;A href="http://dev.splunk.com/view/webframework-developapps/SP-CAAAEWY" target="_blank"&gt;http://dev.splunk.com/view/webframework-developapps/SP-CAAAEWY&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;May I know how to define mixture of self defined and token based variable in Javascript search query e.g  variable "filename" and "alertid" in the example follow?&lt;/P&gt;

&lt;P&gt;// partial javascript code:&lt;BR /&gt;
var alertid= tokens.get("alertid_token");   //tokens received&lt;BR /&gt;
var filename = "1512234117_372926.png";  //own created variable&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   // Search Manager - Make a search using tokens obtained
    var search = new SearchManager({
        "id": "search_img",
        "earliest_time": "-5m@m",
        "latest_time": "now",
        "search":"| imgsearch alertid filename",  // are these variable format correct?
        "cancelOnUnload": true,
        "autostart": false,
       "auto_cancel": 90,
        "preview": false,
        "cache": false
    });
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:00:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Self-defined-variable-format-in-javascript-search-query/m-p/311045#M164643</guid>
      <dc:creator>clement</dc:creator>
      <dc:date>2020-09-29T17:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: Self defined variable format in javascript search query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Self-defined-variable-format-in-javascript-search-query/m-p/311046#M164644</link>
      <description>&lt;P&gt;@clement, I believe &lt;CODE&gt;imgsearch&lt;/CODE&gt; is your custom SPL command. The tokens in search string should be placed withing dollar signs i.e. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  imgsearch $filename$ $alert_id$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is what your search might look like with the changes.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var search = new SearchManager({
            "id": "search_img",
            "earliest_time": "-5m@m",
            "latest_time": "now",
            "search": "|  imgsearch $filename$ $alert_id$",
            "cancelOnUnload": true,
            "autostart": false,
            "auto_cancel": 90,
            "preview": false,
            "cache": false,
            "tokenDependencies": {
            },
            "runWhenTimeIsUndefined": false
        }, {tokens: true, tokenNamespace: "submitted"});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: From &lt;CODE&gt;Splunk Enterprise 6.5&lt;/CODE&gt; onward, if you are &lt;CODE&gt;not using HTML Dashboards&lt;/CODE&gt; you should have &lt;CODE&gt;&amp;lt;init&amp;gt;&lt;/CODE&gt; section in &lt;CODE&gt;Simple XML dashboard&lt;/CODE&gt; which should allow you to initialize your own static tokens like &lt;CODE&gt;filename&lt;/CODE&gt;. Which implies you do not require Simple XML JavaScript Extension for such scenarios. (PS: init section does not work in HTML Dashboard or after conversion to HTML Dashboard.)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;init&amp;gt;
    &amp;lt;set token="filename"&amp;gt;1512234117_372926.png&amp;lt;/set&amp;gt;
  &amp;lt;/init&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Dec 2017 18:23:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Self-defined-variable-format-in-javascript-search-query/m-p/311046#M164644</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-12-02T18:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Self defined variable format in javascript search query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Self-defined-variable-format-in-javascript-search-query/m-p/311047#M164645</link>
      <description>&lt;P&gt;@niketnilay, thank you for your reply.&lt;/P&gt;

&lt;P&gt;I tested your suggestion, however it is not working.&lt;/P&gt;

&lt;P&gt;The two "console.log(alertid);" and "console.log(filename);" before search execution output are correct, but "Search started" or "search:done" status is not shown.&lt;/P&gt;

&lt;P&gt;Please find the my complete JS code follows:&lt;/P&gt;

&lt;P&gt;require([&lt;BR /&gt;
    "splunkjs/mvc",&lt;BR /&gt;
    "splunkjs/mvc/searchmanager",&lt;BR /&gt;
    "splunkjs/mvc/simplexml/ready!"&lt;BR /&gt;
], function(mvc) {&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var SearchManager = require("splunkjs/mvc/searchmanager");

// Get the Events table
var myEventsTable = mvc.Components.get('myevents');


// Respond to a click event
myEventsTable.on("click", function(e) {


    // Get the default model
    var tokens = mvc.Components.get("default");
    var alertid= tokens.get("src_type_tok");
    var ctime = new Date().getTime();

    // create file and path var
    var filename = ctime + "_" + alertid + ".png";

    console.log(alertid);
    console.log(filename);

    var search = new SearchManager({
         "id": "search_img",
         "earliest_time": "-5m@m",
         "latest_time": "now",
         "search": "| imgsearch $alertid$ $filename$",    // this one not working
       //"search": "| imgsearch 3215687 153857376_3215687.png",   // this is working fine
         "cancelOnUnload": true,
         "autostart": false,
         "auto_cancel": 90,
         "preview": false,
         "cache": false,
         "tokenDependencies": {
         },
         "runWhenTimeIsUndefined": false
    }, {tokens: true, tokenNamespace: "submitted"});

    console.log("after search function");

    search.on('search:failed', function() {
        console.log("Search failed");
    }.bind(this));

    search.on("search:start", function() {
        console.log("Search started");
    }.bind(this));

    search.on("search:done", function() {
        console.log("Search completed");
    }.bind(this));

    // Start the search
    search.startSearch();
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;});&lt;/P&gt;</description>
      <pubDate>Sun, 03 Dec 2017 13:20:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Self-defined-variable-format-in-javascript-search-query/m-p/311047#M164645</guid>
      <dc:creator>clement</dc:creator>
      <dc:date>2017-12-03T13:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Self defined variable format in javascript search query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Self-defined-variable-format-in-javascript-search-query/m-p/311048#M164646</link>
      <description>&lt;P&gt;@clement, what you are trying to do can be done in Simple XML itself. Any specific reason for JavaScript?&lt;/P&gt;</description>
      <pubDate>Sun, 03 Dec 2017 14:33:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Self-defined-variable-format-in-javascript-search-query/m-p/311048#M164646</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-12-03T14:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: Self defined variable format in javascript search query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Self-defined-variable-format-in-javascript-search-query/m-p/311049#M164647</link>
      <description>&lt;P&gt;@niketnilay, indeed you have just highlighted a good pointer for me to find a workaround, thank you.&lt;/P&gt;

&lt;P&gt;I refer to the following workaround, it work fine for my requirement:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/239159/multiple-base-searches-in-a-dasboard-with-post-pro.html"&gt;https://answers.splunk.com/answers/239159/multiple-base-searches-in-a-dasboard-with-post-pro.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Thanks again for sharing your information &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 07:39:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Self-defined-variable-format-in-javascript-search-query/m-p/311049#M164647</guid>
      <dc:creator>clement</dc:creator>
      <dc:date>2017-12-04T07:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: Self defined variable format in javascript search query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Self-defined-variable-format-in-javascript-search-query/m-p/311050#M164648</link>
      <description>&lt;P&gt;@clement, seems like you are using post processing to overcome the issue you were facing. While init section to initialize token is a different approach. But I am glad you found something working for you.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 08:08:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Self-defined-variable-format-in-javascript-search-query/m-p/311050#M164648</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-12-04T08:08:14Z</dc:date>
    </item>
  </channel>
</rss>

