All Apps and Add-ons

Splunk Web Framework Tokens cannot be used as a boolean

aelliott
Motivator

Is it possible to use a splunk token as a boolean?
For example, I have a chart that I would like to toggle between using my custom drilldown and showing the search results( because apparently there is no "view results" link at the bottom of the web framework charts).
I have a dropdown that has "True" and "False" in it along with a chart as below.
When setting drilldownRedirect="False" it redirects anyway, however drilldownRedirect=False works fine, which is why the below chart setup fails.
{% chart
id="volumeby-timechart" managerid="user-search"
drilldown="all"
drilldownRedirect="$drilldown$" |token_safe
resizable=True
preview=True
type="bar" %}

I would think that this functionality would be very helpful as you could set other True/False variables as well with tokens.

Does anyone have a workaround for this?

0 Karma
1 Solution

dfoster_splunk
Splunk Employee
Splunk Employee

Well the workaround is to always set boolean values. Tokens do support carrying boolean values in addition to strings.

The behavior you're seeing is probably because the string "False" is truthy from the perspective of JavaScript and therefore looks like the boolean value "true".

View solution in original post

0 Karma

dfoster_splunk
Splunk Employee
Splunk Employee

Well the workaround is to always set boolean values. Tokens do support carrying boolean values in addition to strings.

The behavior you're seeing is probably because the string "False" is truthy from the perspective of JavaScript and therefore looks like the boolean value "true".

0 Karma

aelliott
Motivator

Thanks! I first attempted to link directly to the dropdown with a value of true and false, and that didn't work, but creating a custom javascript method on change of the dropdown with strings in the dropdown value did work. Thanks!

0 Karma

dfoster_splunk
Splunk Employee
Splunk Employee

Not quite. If you have resizable="$resize$"|token_safe (with the quotes, as required by template tags) you can do splunkjs.mvc.Components.get('default').set('resize', true);

A setting that consists of a single token (like "$resize$") can accept a token value of any type, not just strings.

0 Karma

aelliott
Motivator

but can you use it as a boolean such as resizable=$resize$|token_safe in the above function?

That returns an error.

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...