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!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...