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

elliotproebstel
Champion

The code for getting and setting token values via JavaScript looks like this:

// Access the "default" token model
var tokens = mvc.Components.get("default");

// Retrieve the value of a token $mytoken$
var tokenValue = tokens.get("mytoken");

// Change the value of a token $mytoken$
tokens.set("mytoken", "this is the new value");

Those are taken directly from the Splunk developer guide. I'd recommend starting at the section called "Bind data using tokens". It's pretty short and straightforward.

0 Karma

sdawsonkg
Path Finder

if you convert simple xml to html, you still will not be able to decide the ids for the input tags, it will be something like

Get Updates on the Splunk Community!

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...