Dashboards & Visualizations

Setting token programatically when token has selectFirstChoice=true

delewis13
Explorer

Setting tokens in Splunk programatically in Splunk via JS is pretty easy, as documented at:

https://dev.splunk.com/enterprise/docs/developapps/webframework/binddatausingtokens/getandsettokenva...

However, the code snippet at that link appears to have no effect on tokens with true

I have developed the following workaround...

require([
  "underscore",
  "jquery",
  "splunkjs/mvc",
  "splunkjs/mvc/simplexml/ready!"
], function (_, $, mvc) {
  var tokens = mvc.Components.get("default");
  var tokenName = "myTokenName";
  var tokenValue = "myTokenValue";

  tokens._events[`change:${myTokenName}`][0].context.attributes.selectFirstChoice = false

  tokens.set(myTokenName, myTokenValue);
});

Evidently however, this is a hack, as it reaches into the _events attribute which is marked as not a public API.
Thus, I would like a more elegant solution. Any ideas?

Cheers 🙂

Labels (1)

rvany
Communicator

@delewis13 could you please paste your corresponding dashboard code?

0 Karma

anmolpatel
Builder

@delewis13 not a direct answer to the question, though have a look at this app: Splunk Dev For All
https://splunkbase.splunk.com/app/4104/

It has a good walkthrough no how to use JS with Splunk to do this sort of task.

0 Karma
Get Updates on the Splunk Community!

Aligning Observability Costs with Business Value: Practical Strategies

 Join us for an engaging Tech Talk on Aligning Observability Costs with Business Value: Practical ...

Mastering Data Pipelines: Unlocking Value with Splunk

 In today's AI-driven world, organizations must balance the challenges of managing the explosion of data with ...

Splunk Up Your Game: Why It's Time to Embrace Python 3.9+ and OpenSSL 3.0

Did you know that for Splunk Enterprise 9.4, Python 3.9 is the default interpreter? This shift is not just a ...