<?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 use token in javascript file in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-token-in-javascript-file/m-p/470188#M30866</link>
    <description>&lt;P&gt;First you need to set a ID for your multiselect. &lt;/P&gt;

&lt;P&gt;for example - &lt;/P&gt;

&lt;P&gt;then you need to define the js like the following. &lt;/P&gt;

&lt;P&gt;require([&lt;BR /&gt;
 'underscore',&lt;BR /&gt;
 'jquery',&lt;BR /&gt;
 'splunkjs/mvc',&lt;BR /&gt;
'splunkjs/mvc/utils',&lt;BR /&gt;
'splunkjs/mvc/tokenutils',&lt;BR /&gt;
 'splunkjs/mvc/simplexml/ready!'], function(_, $, mvc, utils, TokenUtils){&lt;BR /&gt;
    var tokens = mvc.Components.get('default');&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var abcvalue = splunkjs.mvc.Components.getInstance("abcselect"); // default value is getting captured here
if (abcvalue != undefined) {
    abcvalue.on("change", function(e){
        console.log("abc changed to "+tokens.get("abc")); //on token change the value gets captured into through tokens.get("abc")
        define your function here
    });
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;});&lt;/P&gt;

&lt;P&gt;Also please remember to put the JS file in $SPLUNK_APP$/appserver/static folder &lt;/P&gt;</description>
    <pubDate>Tue, 03 Sep 2019 04:00:42 GMT</pubDate>
    <dc:creator>sandyIscream</dc:creator>
    <dc:date>2019-09-03T04:00:42Z</dc:date>
    <item>
      <title>How to use token in javascript file</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-token-in-javascript-file/m-p/470186#M30864</link>
      <description>&lt;P&gt;I have a multiselect panel on my dashboard and js file attached to the dashboard as well. How do i pass the token value from the multiselect into the javascript file?&lt;/P&gt;

&lt;P&gt;e.g.:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard script="xyz.js"&amp;gt;
  &amp;lt;label&amp;gt;xyz&amp;lt;/label&amp;gt;

&amp;lt;fieldset submitButton="false"&amp;gt;
&amp;lt;input type="multiselect" token="filter.abc" searchWhenChanged="true"&amp;gt;
  &amp;lt;label&amp;gt;abc&amp;lt;/label&amp;gt;
  &amp;lt;fieldForLabel&amp;gt;abc&amp;lt;/fieldForLabel&amp;gt;
  &amp;lt;fieldForValue&amp;gt;abc&amp;lt;/fieldForValue&amp;gt;
  &amp;lt;search&amp;gt;
    &amp;lt;query&amp;gt;index="index" | stats count by abc&amp;lt;/query&amp;gt;
    &amp;lt;earliest&amp;gt;0&amp;lt;/earliest&amp;gt;
    &amp;lt;latest&amp;gt;&amp;lt;/latest&amp;gt;
  &amp;lt;/search&amp;gt;
  &amp;lt;choice value="*"&amp;gt;All&amp;lt;/choice&amp;gt;
  &amp;lt;default&amp;gt;*&amp;lt;/default&amp;gt;
&amp;lt;/input&amp;gt;


&amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
            &amp;lt;div class="bk-root" id="dbdf03be-ce3a-4730-a185-e613c25394f9" data-root-id="1190"/&amp;gt;
        &amp;lt;/html&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;What do I need to change in the xyz.js so that it would be able to read the $abc$ token?&lt;/P&gt;</description>
      <pubDate>Mon, 02 Sep 2019 07:25:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-token-in-javascript-file/m-p/470186#M30864</guid>
      <dc:creator>viandyg</dc:creator>
      <dc:date>2019-09-02T07:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to use token in javascript file</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-token-in-javascript-file/m-p/470187#M30865</link>
      <description>&lt;P&gt;First you need to set a ID for your multiselect. &lt;/P&gt;

&lt;P&gt;for example - &lt;/P&gt;

&lt;P&gt;then you need to define the js like the following. &lt;/P&gt;

&lt;P&gt;require([&lt;BR /&gt;
 'underscore',&lt;BR /&gt;
 'jquery',&lt;BR /&gt;
 'splunkjs/mvc',&lt;BR /&gt;
'splunkjs/mvc/utils',&lt;BR /&gt;
'splunkjs/mvc/tokenutils',&lt;BR /&gt;
 'splunkjs/mvc/simplexml/ready!'], function(_, $, mvc, utils, TokenUtils){&lt;BR /&gt;
    var tokens = mvc.Components.get('default');&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var abcvalue = splunkjs.mvc.Components.getInstance("abcselect"); // default value is getting captured here
if (abcvalue != undefined) {
    abcvalue.on("change", function(e){
        console.log("abc changed to "+tokens.get("abc")); //on token change the value gets captured into through tokens.get("abc")
        define your function here
    });
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;});&lt;/P&gt;

&lt;P&gt;Also please remember to put the JS file in $SPLUNK_APP$/appserver/static folder &lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 04:00:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-token-in-javascript-file/m-p/470187#M30865</guid>
      <dc:creator>sandyIscream</dc:creator>
      <dc:date>2019-09-03T04:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to use token in javascript file</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-token-in-javascript-file/m-p/470188#M30866</link>
      <description>&lt;P&gt;First you need to set a ID for your multiselect. &lt;/P&gt;

&lt;P&gt;for example - &lt;/P&gt;

&lt;P&gt;then you need to define the js like the following. &lt;/P&gt;

&lt;P&gt;require([&lt;BR /&gt;
 'underscore',&lt;BR /&gt;
 'jquery',&lt;BR /&gt;
 'splunkjs/mvc',&lt;BR /&gt;
'splunkjs/mvc/utils',&lt;BR /&gt;
'splunkjs/mvc/tokenutils',&lt;BR /&gt;
 'splunkjs/mvc/simplexml/ready!'], function(_, $, mvc, utils, TokenUtils){&lt;BR /&gt;
    var tokens = mvc.Components.get('default');&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var abcvalue = splunkjs.mvc.Components.getInstance("abcselect"); // default value is getting captured here
if (abcvalue != undefined) {
    abcvalue.on("change", function(e){
        console.log("abc changed to "+tokens.get("abc")); //on token change the value gets captured into through tokens.get("abc")
        define your function here
    });
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;});&lt;/P&gt;

&lt;P&gt;Also please remember to put the JS file in $SPLUNK_APP$/appserver/static folder &lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 04:00:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-token-in-javascript-file/m-p/470188#M30866</guid>
      <dc:creator>sandyIscream</dc:creator>
      <dc:date>2019-09-03T04:00:42Z</dc:date>
    </item>
  </channel>
</rss>

