Dashboards & Visualizations

Tokens Usage in Javascript Code

dm2001
New Member

Hi, may I know any documentation on how tokens work when using them in javascript files. The docs at https://docs.splunk.com/Documentation/Splunk/9.1.2/Viz/tokens don't present much info on Javascript usage.

Particularly, I am trying to use tokens to delete KV store values and I am confused how this can be done. Just using tokens.unset() is not working.

Any help would be appreciated!!

Labels (1)
0 Karma

garenilla
Explorer

Hi @dm2001 , it's been a long since I used tokens on JavaScript but when I used them I usually had these methods:

var defaultTokenModel = mvc.Components.getInstance('default', {
    create: true
});
var submittedTokenModel = mvc.Components.getInstance('submitted', {
    create: true
});

function setToken(name, value) {
    defaultTokenModel.set(name, value);
    submittedTokenModel.set(name, value);
};
function unsetToken(name) {
    defaultTokenModel.unset(name);
    submittedTokenModel.unset(name);
};

Then in your JS you can use the methods freely to set any token to a value or unset them.

I hope it helps.

 

0 Karma
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...