Dashboards & Visualizations

How to use token in javascript file

viandyg
Engager

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?

e.g.:

<dashboard script="xyz.js">
  <label>xyz</label>

<fieldset submitButton="false">
<input type="multiselect" token="filter.abc" searchWhenChanged="true">
  <label>abc</label>
  <fieldForLabel>abc</fieldForLabel>
  <fieldForValue>abc</fieldForValue>
  <search>
    <query>index="index" | stats count by abc</query>
    <earliest>0</earliest>
    <latest></latest>
  </search>
  <choice value="*">All</choice>
  <default>*</default>
</input>


<row>
    <panel>
      <html>
            <div class="bk-root" id="dbdf03be-ce3a-4730-a185-e613c25394f9" data-root-id="1190"/>
        </html>
    </panel>
  </row>
</dashboard>

What do I need to change in the xyz.js so that it would be able to read the $abc$ token?

0 Karma

sandyIscream
Communicator

First you need to set a ID for your multiselect.

for example -

then you need to define the js like the following.

require([
'underscore',
'jquery',
'splunkjs/mvc',
'splunkjs/mvc/utils',
'splunkjs/mvc/tokenutils',
'splunkjs/mvc/simplexml/ready!'], function(_, $, mvc, utils, TokenUtils){
var tokens = mvc.Components.get('default');

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
    });
}

});

Also please remember to put the JS file in $SPLUNK_APP$/appserver/static folder

0 Karma

sandyIscream
Communicator

First you need to set a ID for your multiselect.

for example -

then you need to define the js like the following.

require([
'underscore',
'jquery',
'splunkjs/mvc',
'splunkjs/mvc/utils',
'splunkjs/mvc/tokenutils',
'splunkjs/mvc/simplexml/ready!'], function(_, $, mvc, utils, TokenUtils){
var tokens = mvc.Components.get('default');

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
    });
}

});

Also please remember to put the JS file in $SPLUNK_APP$/appserver/static folder

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...