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!

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...