Dashboards & Visualizations

How to set and unset token after submit and what should be depends condition in row/panel?

dkssingh2005
Explorer

I have requirement  after  submit I need to hide and show row's panel on the condition of dropdown. when day is selected then show panel 1 and when hour is selected then show panel 2. I have queries in panel so that I don't want execute it also by adding the token condition. 

 

<fieldset submitButton="true" autoRun="false">
              <input type="dropdown" token="timespan">
                      <label>Time Span</label>
                     <choice value="1h">Hour</choice>
                      <choice value="1d">Day</choice>
                      <initialValue>1d</initialValue>
                     <default>1d</default>
              </input>
</fieldset>

<row depends=???> ----- --panel 1

<row depends=???> --------panel 2

 

How to set and unset token after submit and what should be depends condition in row/panel?

Labels (2)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

Just hiding the row with depends="$token$" will not prevent the query from running - you need to add the depends to the search too.

Have a look at this dashboard - it uses a dummy row to have a search that sets/clears a token (is_hour) depending on the result of the setting, which will run after the submit is clicked. It will then set the token is_hour (or clear it). The subsequent two rows can then use depends/rejects to show/hide and run/not run the search.

<form>
  <label>test</label>
  <fieldset submitButton="true">
    <input type="dropdown" token="timespan">
      <label>Time Span</label>
      <choice value="1h">Hour</choice>
      <choice value="1d">Day</choice>
      <initialValue>1d</initialValue>
      <default>1d</default>
    </input>
  </fieldset>
  <row depends="$hidden$">
    <panel>
      <table>
        <title>is_hour=$is_hour$</title>
        <search>
          <query>| makeresults
          | eval Type=$timespan|s$
          </query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
          <done>
            <eval token="is_hour">if($result.Type$="1h", "hour", null())</eval>
          </done>
        </search>
        <option name="count">100</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="rowNumbers">false</option>
        <option name="totalsRow">false</option>
        <option name="wrap">true</option>
      </table>
    </panel>
  </row>
  <row depends="$is_hour$">
    <panel>
      <table>
        <title>Hour search</title>
        <search depends="$is_hour$">
          <query>| makeresults
          | eval Type="ByHour"
          </query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">100</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="rowNumbers">false</option>
        <option name="totalsRow">false</option>
        <option name="wrap">true</option>
      </table>
    </panel>
  </row>
  <row rejects="$is_hour$">
    <panel>
      <table>
        <title>Day search</title>
        <search rejects="$is_hour$">
          <query>| makeresults
          | eval Type="ByDay"
          </query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">100</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="rowNumbers">false</option>
        <option name="totalsRow">false</option>
        <option name="wrap">true</option>
      </table>
    </panel>
  </row>
</form>

 

View solution in original post

dkssingh2005
Explorer

yes, I am able to do by adding change handler . Below are the code snippet.  But I need after submit. Is there any way ?

<change>
<condition label="Hour">
<set token="show_hour">y</set>
<unset token="show_day"></unset>
</condition>
<condition label="Day">
<set token="show_day">y</set>
<unset token="show_hour"></unset>
</condition>
</change>

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Just hiding the row with depends="$token$" will not prevent the query from running - you need to add the depends to the search too.

Have a look at this dashboard - it uses a dummy row to have a search that sets/clears a token (is_hour) depending on the result of the setting, which will run after the submit is clicked. It will then set the token is_hour (or clear it). The subsequent two rows can then use depends/rejects to show/hide and run/not run the search.

<form>
  <label>test</label>
  <fieldset submitButton="true">
    <input type="dropdown" token="timespan">
      <label>Time Span</label>
      <choice value="1h">Hour</choice>
      <choice value="1d">Day</choice>
      <initialValue>1d</initialValue>
      <default>1d</default>
    </input>
  </fieldset>
  <row depends="$hidden$">
    <panel>
      <table>
        <title>is_hour=$is_hour$</title>
        <search>
          <query>| makeresults
          | eval Type=$timespan|s$
          </query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
          <done>
            <eval token="is_hour">if($result.Type$="1h", "hour", null())</eval>
          </done>
        </search>
        <option name="count">100</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="rowNumbers">false</option>
        <option name="totalsRow">false</option>
        <option name="wrap">true</option>
      </table>
    </panel>
  </row>
  <row depends="$is_hour$">
    <panel>
      <table>
        <title>Hour search</title>
        <search depends="$is_hour$">
          <query>| makeresults
          | eval Type="ByHour"
          </query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">100</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="rowNumbers">false</option>
        <option name="totalsRow">false</option>
        <option name="wrap">true</option>
      </table>
    </panel>
  </row>
  <row rejects="$is_hour$">
    <panel>
      <table>
        <title>Day search</title>
        <search rejects="$is_hour$">
          <query>| makeresults
          | eval Type="ByDay"
          </query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">100</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="rowNumbers">false</option>
        <option name="totalsRow">false</option>
        <option name="wrap">true</option>
      </table>
    </panel>
  </row>
</form>

 

ITWhisperer
SplunkTrust
SplunkTrust

Add a change handler block to the input and set tokens there dependent on the selection made

Get Updates on the Splunk Community!

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Shape the Future of Splunk: Join the Product Research Lab!

Join the Splunk Product Research Lab and connect with us in the Slack channel #product-research-lab to get ...