Dashboards & Visualizations

Set Token Not working when values in Drop down is changed in Dashboard

Chiddarthan
New Member

First time when dashboard is loading change condition is detected and correct part is replaced in Web Request Panel. When i change the value in drop down, Change condition is not getting recognized and query in panel is like below

"cart | timechart count"

 

<form>
   <label>Test</label>
   <fieldset submitButton="false" autoRun="true">
      <input type="time" token="timePicker">
         <label />
         <default>
            <earliest>-4h@m</earliest>
            <latest>now</latest>
         </default>
      </input>
      <input type="dropdown" token="serviceName">
         <label>Service</label>
         <choice value="">Select a Service</choice>
         <choice value="lpd">LPD</choice>
         <choice value="cart">Cart</choice>
         <choice value="identity">Identity</choice>
         <default>Select a Service</default>
         <initialValue>Select a Service</initialValue>
         <change>
            <condition value="lpd">
               <set token="serviceName">index=test1</set>
            </condition>
            <condition value="cart">
               <set token="serviceName">index=test2</set>
            </condition>
            <condition value="identity">
               <set token="serviceName">index=test3</set>
            </condition>
         </change>
      </input>
      <input type="radio" token="byHost" searchWhenChanged="true">
         <label>By Host</label>
         <choice value="by host">Yes</choice>
         <choice value="">No</choice>
         <default>by host</default>
         <initialValue>by host</initialValue>
      </input>
   </fieldset>
   <row>
      <panel>
         <title>Web Request</title>
         <chart>
            <search>
               <query>$serviceName$ | timechart count</query>
               <earliest>$timePicker.earliest$</earliest>
               <latest>$timePicker.latest$</latest>
            </search>
            <option name="charting.chart">line</option>
         </chart>
      </panel>
   </row>
</form>

 

Labels (2)
0 Karma

dmarling
Builder

You have token contention for the serviceName token which is what is causing your issue.  You are using change to set the token that you are also using as the token for the drop down selector.  You need to make a choice on how you want the token to be populated, either have the drop down selections populate serviceName or the change event on the input.  The quickest fix is to just assign a different token to the drop down selector:

<form>
  <label>Test</label>
  <fieldset submitButton="false" autoRun="true">
    <input type="time" token="timePicker">
      <label></label>
      <default>
        <earliest>-4h@m</earliest>
        <latest>now</latest>
      </default>
    </input>
    <input type="dropdown" token="serviceNamedropdown">
      <label>Service</label>
      <choice value="">Select a Service</choice>
      <choice value="lpd">LPD</choice>
      <choice value="cart">Cart</choice>
      <choice value="identity">Identity</choice>
      <default>Select a Service</default>
      <initialValue>Select a Service</initialValue>
      <change>
        <condition value="lpd">
          <set token="serviceName">index=test1</set>
        </condition>
        <condition value="cart">
          <set token="serviceName">index=test2</set>
        </condition>
        <condition value="identity">
          <set token="serviceName">index=test3</set>
        </condition>
      </change>
    </input>
    <input type="radio" token="byHost" searchWhenChanged="true">
      <label>By Host</label>
      <choice value="by host">Yes</choice>
      <choice value="">No</choice>
      <default>by host</default>
      <initialValue>by host</initialValue>
    </input>
  </fieldset>
  <row>
    <panel>
      <title>Web Request</title>
      <chart>
        <search>
          <query>$serviceName$ | timechart count</query>
          <earliest>$timePicker.earliest$</earliest>
          <latest>$timePicker.latest$</latest>
        </search>
        <option name="charting.chart">line</option>
      </chart>
    </panel>
  </row>
</form>
If this comment/answer was helpful, please up vote it. Thank you.
0 Karma

niketn
Legend

@Chiddarthan you would also need to enable searchWhenChanged="true" for the dropdown

<input type="dropdown" token="serviceNamedropdown" searchWhenChanged="true">


Rest all code remains the same as you originally posted.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...