Dashboards & Visualizations

Use token in the dropdown choice value

karthi25
Path Finder

I have a dropdown with choice values as follows:

        <label>SELECT A TASK NAME</label>

        <choice value="taskName='aaa' status='COMPLETED'| sort -splunkLogId | eval startDateModified= strptime( startDate, &quot;%Y-%m-%d %H:%M:%S&quot;) | eval newDateFromDash = relative_time($dashboardTime.latest$(), &quot;$dashboardTime.earliest$&quot;)
 | where startDateModified > newDateFromDash | eval runDate = strftime(strptime(startDate, &quot;%Y-%m-%d&quot;),&quot;%Y-%m-%d&quot;) |chart sum(rowCount) over runDate">aaa</choice>

        <choice value="taskName='bbb' status='COMPLETED'| sort -splunkLogId |eval startDateModified= strptime( startDate, &quot;%Y-%m-%d %H:%M:%S&quot;) | eval newDateFromDash = relative_time($dashboardTime.latest$(), &quot;$dashboardTime.earliest$&quot;)
 | eval runDate = strftime(strptime(startDate, &quot;%Y-%m-%d&quot;),&quot;%Y-%m-%d&quot;) |chart sum(rowCount) over runDate">bbb</choice>
        .....
        <selectFirstChoice>true</selectFirstChoice>
      </input>

"dashboardTime" is nothing but my time select box token. But the choice value is not getting update with the corresponding values of $dashboardTime.latest$ and $dashboardTime.earliest$ instead it is update with the string "$dashboardTime.latest$ " and "$dashboardTime.earliest$".
Can anyone please suggest me to do it.

0 Karma

bojanisch
Path Finder

Have you set searchWhenChanged = true on the time range picker?

Alternatively why do you parse the time token in your queries? I suggest you to use a changed snippet that transforms the time string constraint directly into an epoch value that can be used in your queries:

<change>
    <eval token="earliest">if(isnum($time.earliest$), $time.earliest$, relative_time(now(), $time.earliest$))</eval>
    <eval token="latest">if(isnum($time.latest$), $time.latest$, relative_time(now(), $time.latest$))</eval>
</change>

You can simply add this to the input definition of your time range picker and use the new tokens $earliest$ and $latest$ for time comparisons. You could also add more tokens and formations, depending on your needs.

Oh and by the way, in your example (your first query) you also need to escape > into &gt; .

0 Karma

493669
Super Champion

also share my time select box query to understand better

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...