Dashboards & Visualizations

how change the value of a token in JS?

renanprado96
Path Finder

I want to insert the value of a date on a token:
I will choose for INPUT HTML.
Clicking a <button>, I wanted to set the chosen date in token

<input type="date" id="myDate" name="bday" min="2015-01-02" max="2030-01-02">
 <button onclick="setarToken();"> Mostrar data </button>

I made a function like this:

 function setarToken(){
     var myDateFn = document.getElementById("myDate").value;   // Here get the date of INPUT

      // And here I have that insert the date(myDateFn) in the token 
     // Something like
            $myToken$ = myDateFn ;
 }

Thanks!

0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Use yourTokenModel.set("myToken", myDateFn);.

View solution in original post

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Use yourTokenModel.set("myToken", myDateFn);.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

If "submitted" is the ID of your token model, you can load the actual object like this:

mvc.Components.getInstance('submitted', {create: true})

That's assuming you have the splunkjs/mvc class stored under that name, and it'll create a new token model if that ID doesn't exist yet.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

yourTokenModel is the variable pointing at your token model, containing the tokens of your dashboard.

http://dev.splunk.com/view/SP-CAAAEQB

0 Karma

renanprado96
Path Finder

So in this example, the token model is submitted?

 new SearchManager({
        "id": "search1",
        "search": "index=_internal sourcetype=$sourcetype$ | head $choices$",
        "earliest_time": "$earliest$",
        "latest_time": "now",
        "preview": true
    }, {tokens: true, tokenNamespace: "submitted"});
0 Karma

renanprado96
Path Finder

what is yourTokenModel? or Token Model?
I did not understand.
Thanks!

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...