Dashboards & Visualizations

I have two conditions that need to be compared to set token value in a second dropdown

handsomehari
Explorer

I have two conditions needs to be compared to set token value in the second dropdown. First condition from dropdown 1 (token="view") and second condition from dropdown 2 ( token="category"). Please tell us if there is any alternative way of doing this.

    <input type="dropdown" token="view">d<label>View</label>
      <choice value="A">A</choice>
      <choice value="B">B</choice>
      <default>A</default>
    </input>
    <input type="dropdown" token="category">
      <label>Category</label>
      <choice value="X">X</choice>
      <choice value="Y">Y</choice>
      <change>
      <!-- Something like below condition i need -->
        <condition value="X">
            <condition match="$view% == 'A'">
                <set token="showX">Test1</set>
            </condition>
            <condition match="$view% == 'B'">
                <set token="showX">Test2</set>
            </condition>
        </condition>
        <condition value="Y">
            <unset token="showX">Test 3</unset>
        </condition>
      </change>
    </input>
0 Karma
1 Solution

niketn
Legend

@handsomehari, try the following to use <eval> tag in Simple XML to set the token value based on condition.
PS: Since your showX token is depended on both Dropdowns, you would also need to created <change> Event Handler for view, dropdown to set and unset showX token similar (but inverse) to the logic in the category dropdown:

  <fieldset submitButton="false">
    <input type="dropdown" token="view" searchWhenChanged="true">
      <label>View</label>
      <choice value="A">A</choice>
      <choice value="B">B</choice>
      <default>A</default>
      <change>
        <condition value="A">
          <eval token="showX">case($category$=="X","Test1",$category$=="Y",$showX$)</eval>
        </condition>
        <condition value="B">
          <eval token="showX">case($category$=="X","Test2",$category$=="Y",$showX$)</eval>
        </condition>
      </change>
    </input>
    <input type="dropdown" token="category" searchWhenChanged="true">
      <label>Category</label>
      <choice value="X">X</choice>
      <choice value="Y">Y</choice>
      <change>
        <condition value="X">
          <eval token="showX">case($view$=="A","Test1",$view$=="B","Test2")</eval>
        </condition>
        <condition value="Y">
          <unset token="showX"></unset>
        </condition>
      </change>
    </input>    
  </fieldset>

PS: The $category$=="Y",$showX$, unsets the showX token as per requirement.
Following HTML Panel can be added to test the tokens:

  <row>
    <panel>
      <html>
        <b>Token Values</b><br/>
        <div>
          view: $view$<br/>
          category: $category$<br/>
          showX: $showX$<br/>
        </div>  
      </html>
    </panel>
  </row>

Please try out and confirm.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

0 Karma

niketn
Legend

@handsomehari, try the following to use <eval> tag in Simple XML to set the token value based on condition.
PS: Since your showX token is depended on both Dropdowns, you would also need to created <change> Event Handler for view, dropdown to set and unset showX token similar (but inverse) to the logic in the category dropdown:

  <fieldset submitButton="false">
    <input type="dropdown" token="view" searchWhenChanged="true">
      <label>View</label>
      <choice value="A">A</choice>
      <choice value="B">B</choice>
      <default>A</default>
      <change>
        <condition value="A">
          <eval token="showX">case($category$=="X","Test1",$category$=="Y",$showX$)</eval>
        </condition>
        <condition value="B">
          <eval token="showX">case($category$=="X","Test2",$category$=="Y",$showX$)</eval>
        </condition>
      </change>
    </input>
    <input type="dropdown" token="category" searchWhenChanged="true">
      <label>Category</label>
      <choice value="X">X</choice>
      <choice value="Y">Y</choice>
      <change>
        <condition value="X">
          <eval token="showX">case($view$=="A","Test1",$view$=="B","Test2")</eval>
        </condition>
        <condition value="Y">
          <unset token="showX"></unset>
        </condition>
      </change>
    </input>    
  </fieldset>

PS: The $category$=="Y",$showX$, unsets the showX token as per requirement.
Following HTML Panel can be added to test the tokens:

  <row>
    <panel>
      <html>
        <b>Token Values</b><br/>
        <div>
          view: $view$<br/>
          category: $category$<br/>
          showX: $showX$<br/>
        </div>  
      </html>
    </panel>
  </row>

Please try out and confirm.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

handsomehari
Explorer

Thanks!! It is working for me..

0 Karma
Get Updates on the Splunk Community!

Developer Spotlight with Paul Stout

Welcome to our very first developer spotlight release series where we'll feature some awesome Splunk ...

State of Splunk Careers 2024: Maximizing Career Outcomes and the Continued Value of ...

For the past four years, Splunk has partnered with Enterprise Strategy Group to conduct a survey that gauges ...

Data-Driven Success: Splunk & Financial Services

Splunk streamlines the process of extracting insights from large volumes of data. In this fast-paced world, ...