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 Splunk Enterprise 9.2

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

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

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 ...