<?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: How to send drilldown tokens in JS? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421119#M27753</link>
    <description>&lt;P&gt;@astatrial the &lt;CODE&gt;on change&lt;/CODE&gt; event fires each time the token value changes, which seemed to be your original ask. However, seems like your use case is different. &lt;/P&gt;

&lt;P&gt;Can you please add more details as to where is the token coming from? Is this form input token or search token or visualization drilldown token or something else?&lt;/P&gt;

&lt;P&gt;Also once the tokens are set in the drilldown why exactly are you trying to use them in JS? Where/which event in JS do you want to use this token?&lt;/P&gt;</description>
    <pubDate>Tue, 23 Apr 2019 17:25:13 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2019-04-23T17:25:13Z</dc:date>
    <item>
      <title>How to send drilldown tokens in JS?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421112#M27746</link>
      <description>&lt;P&gt;Hi, &lt;BR /&gt;
I have a dashboard with drill down that generate tokens. I am trying to send the tokens into JS, but for some reason i get the message "undefined" (on the console screen).&lt;BR /&gt;
When i try to use tokens that are not from the drill down it is working, but it canceling the drill down tokens.&lt;BR /&gt;
I also tried to replace the default token model with submitted but it didn't work.&lt;/P&gt;

&lt;P&gt;This is the part of the JS referring to the tokens: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;// Get the default model
    var defaultTokenModel = splunkjs.mvc.Components.getInstance("default");
// Get some token from there
    var token_def = defaultTokenModel.get("tempp");
console.log(token_def);
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And this is the part of the dashboard with the drill down tokens: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    &amp;lt;drilldown&amp;gt;
      &amp;lt;set token="customm"&amp;gt;$row.Custom$&amp;lt;/set&amp;gt;
      &amp;lt;set token="tempp"&amp;gt;$row.temp$&amp;lt;/set&amp;gt;
    &amp;lt;/drilldown&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks very much!! &lt;/P&gt;</description>
      <pubDate>Sun, 21 Apr 2019 20:19:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421112#M27746</guid>
      <dc:creator>astatrial</dc:creator>
      <dc:date>2019-04-21T20:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to send drilldown tokens in JS?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421113#M27747</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Try this on &lt;CODE&gt;change&lt;/CODE&gt; event&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard script="drilldown.js"&amp;gt;
  &amp;lt;label&amp;gt;drilldowntoken&amp;lt;/label&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;index="_internal" |stats count by source&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;cell&amp;lt;/option&amp;gt;
        &amp;lt;drilldown&amp;gt;
          &amp;lt;set token="source"&amp;gt;$row.source$&amp;lt;/set&amp;gt;
          &amp;lt;set token="count"&amp;gt;$row.count$&amp;lt;/set&amp;gt;
        &amp;lt;/drilldown&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;js:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
    "splunkjs/mvc",
    "splunkjs/mvc/simplexml/ready!",
], function(mvc) {
    $(document).ready(function () {
        var defaultTokenModel = mvc.Components.get("default");
        defaultTokenModel.on("change:source", function(newTokenName, source, options) {
            console.log("source----------------&amp;gt;"+source);
        });
    });

});
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Apr 2019 02:41:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421113#M27747</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-04-22T02:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to send drilldown tokens in JS?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421114#M27748</link>
      <description>&lt;P&gt;@astatrial in Simple XML JS extensions you have to code event handlers so that the token are captured only when an event happens otherwise they will execute only once as soon as JS is loaded (at that point of time the token will never be set).&lt;/P&gt;

&lt;P&gt;You can refer to the following answer and use option 2 to capture change event of the token model to access the new value. Also link to Splunk Dev site for the same: &lt;A href="https://answers.splunk.com/answers/612600/how-to-retrieve-the-value-of-a-token-in-javascript.html"&gt;https://answers.splunk.com/answers/612600/how-to-retrieve-the-value-of-a-token-in-javascript.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Please let us know if you need further assistance.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 02:42:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421114#M27748</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-04-22T02:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to send drilldown tokens in JS?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421115#M27749</link>
      <description>&lt;P&gt;Hi, thanks for you help&lt;BR /&gt;
I added the next lines to my js: &lt;/P&gt;

&lt;P&gt;// Access the "default" token model&lt;BR /&gt;
var defaultTokenModel = mvc.Components.get("default");&lt;BR /&gt;
defaultTokenModel.on("change:customm", function(newTokenName, customm, options) {&lt;BR /&gt;
console.log("source----------------&amp;gt;"+customm);&lt;BR /&gt;
});&lt;/P&gt;

&lt;P&gt;But i got the next error: &lt;/P&gt;

&lt;P&gt;"Uncaught TypeError: Cannot read property 'get' of undefined"&lt;/P&gt;

&lt;P&gt;On the line : &lt;BR /&gt;
var defaultTokenModel = mvc.Components.get("default");&lt;/P&gt;

&lt;P&gt;Also, do i need to use this for multi select tokens too ? &lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 08:04:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421115#M27749</guid>
      <dc:creator>astatrial</dc:creator>
      <dc:date>2019-04-22T08:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to send drilldown tokens in JS?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421116#M27750</link>
      <description>&lt;P&gt;Thanks for your help&lt;BR /&gt;
I didn't understand this part: &lt;/P&gt;

&lt;P&gt;$(document).ready(function ()&lt;/P&gt;

&lt;P&gt;But i added the next lines:&lt;/P&gt;

&lt;P&gt;var defaultTokenModel = mvc.Components.get("default");&lt;BR /&gt;
defaultTokenModel.on("change:customm", function(newTokenName, customm, options) {&lt;BR /&gt;
console.log("source----------------&amp;gt;"+customm);&lt;BR /&gt;
});&lt;/P&gt;

&lt;P&gt;and got the next error:&lt;/P&gt;

&lt;P&gt;"Uncaught TypeError: Cannot read property 'get' of undefined"&lt;/P&gt;

&lt;P&gt;On the line : &lt;BR /&gt;
var defaultTokenModel = mvc.Components.get("default");&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 08:08:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421116#M27750</guid>
      <dc:creator>astatrial</dc:creator>
      <dc:date>2019-04-22T08:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to send drilldown tokens in JS?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421117#M27751</link>
      <description>&lt;P&gt;@astatrial you need to include reference &lt;CODE&gt;'splunkjs/mvc'&lt;/CODE&gt; like following. See if you get any error just &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; require([
      'jquery',
      'splunkjs/mvc',
      'splunkjs/mvc/simplexml/ready!'
  ], function($,mvc){
     console.log("Inside my JS");
     var defaultTokenModel=mvc.Components.get("default");
 });
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can use browser inspector console logs for debugging this. Also you should get Splunk Dashboard Examples App and check out some of the examples to understand CSS and JS Extensions in Splunk. Another good app is Splunk Dev for All and couple of good .Conf sessions from last year!&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 08:58:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421117#M27751</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-04-22T08:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to send drilldown tokens in JS?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421118#M27752</link>
      <description>&lt;P&gt;Hey, &lt;/P&gt;

&lt;P&gt;Update:&lt;BR /&gt;
I used what you suggested with:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;splunkjs.mvc.Components.getInstance("default");
defaultTokenModel.on("change:customm", 
function(newTokenName, customm, options) {
console.log(customm);
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and it works, but i need to use it in a search outside the function of the ".on".&lt;/P&gt;

&lt;P&gt;I read the documentation about the SPLUNK WEB FRAMEWORK but it doesn't include details about that.&lt;/P&gt;

&lt;P&gt;I have tried using "return customm" and some other things with no luck. &lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 09:28:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421118#M27752</guid>
      <dc:creator>astatrial</dc:creator>
      <dc:date>2019-04-22T09:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to send drilldown tokens in JS?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421119#M27753</link>
      <description>&lt;P&gt;@astatrial the &lt;CODE&gt;on change&lt;/CODE&gt; event fires each time the token value changes, which seemed to be your original ask. However, seems like your use case is different. &lt;/P&gt;

&lt;P&gt;Can you please add more details as to where is the token coming from? Is this form input token or search token or visualization drilldown token or something else?&lt;/P&gt;

&lt;P&gt;Also once the tokens are set in the drilldown why exactly are you trying to use them in JS? Where/which event in JS do you want to use this token?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 17:25:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421119#M27753</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-04-23T17:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to send drilldown tokens in JS?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421120#M27754</link>
      <description>&lt;P&gt;I have a button that run "my search":&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$(".button1").on("click", function (){
      var ok = confirm("Are you sure?");
      if (ok){
          mysearch.startSearch();
          alert('Done');
      } //else {
          //    alert('user did not click ok!');
      //}
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to use the token that changes inside the query, for example :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var mysearch = new SearchManager({
    id: "mysearch",
    autostart: "false",
    search: '| makeresults | eval x = "' + $customm$ '"'
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The token is coming from a drill down, when i click on a table row.  &lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 06:44:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421120#M27754</guid>
      <dc:creator>astatrial</dc:creator>
      <dc:date>2019-04-24T06:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to send drilldown tokens in JS?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421121#M27755</link>
      <description>&lt;P&gt;Make sure you have loaded splunkjs/mvc and to the var mvc (position of the argument and module  loading should be same)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
     "splunkjs/mvc",
     "splunkjs/mvc/simplexml/ready!",
 ], function(mvc) {
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Apr 2019 09:20:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421121#M27755</guid>
      <dc:creator>paramagurukarth</dc:creator>
      <dc:date>2019-04-24T09:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to send drilldown tokens in JS?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421122#M27756</link>
      <description>&lt;P&gt;@astatrial if you are using token directly in SearchManager's search string, then you can use token directly using $yourTokenName$. It does not need to be passed using JavaScript.&lt;/P&gt;

&lt;P&gt;Following is an example of Search Manager which queries Splunk's _internal index with token &lt;CODE&gt;tokLogLevel&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var search1 = new SearchManager({
            "id": "search1",
            "status_buckets": 0,
            "search": "index=_internal sourcetype=splunkd log_level=\"$tokLogLevel$\" |  timechart count by component",
            "earliest_time": "-24h@h",
            "latest_time": "now",
            "sample_ratio": 1,
            "cancelOnUnload": true,
            "app": utils.getCurrentApp(),
            "auto_cancel": 90,
            "preview": true,
            "tokenDependencies": {
            },
            "runWhenTimeIsUndefined": false
        }, {tokens: true, tokenNamespace: "submitted"});
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Apr 2019 09:47:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-send-drilldown-tokens-in-JS/m-p/421122#M27756</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-04-25T09:47:07Z</dc:date>
    </item>
  </channel>
</rss>

