Getting Data In

How to change the displayed time filter when a different dropdown value is selected?

stephenggilmore
Explorer

I have two filters on my dashboard. One for time (using the Time filter) and one for environment (using the Dropdown filter). When I select a value from environment, it updates the time token and the dashboard panels correctly. However, it does not change the displayed value in the time filter dropdown.

For example: The dashboard defaults to Environment: Test and Time: Last 60 Minutes. If I change the Environment to Prod, then it changes the Time to Last 24 Hours, but the dropdown does not reflect that, which is confusing.

How do I get the text in the time dropdown to update when I select a value from another dropdown?

  <init>
    <set token="index">test</set>
    <set token="time"> -60m@m</set>
  </init>
  <label>Test Dashboard</label>
  <description>Test description.</description>
  <fieldset submitButton="false">
    <input type="time" token="time">
      <label>Time-Picker</label>
      <default>
        <earliest>-60m@m</earliest>
        <latest>now</latest>
      </default>
    </input>
    <input type="dropdown" token="index" searchWhenChanged="true">
      <label>Environment</label>
      <choice value="prod">Prod</choice>
      <choice value="test">Test</choice>
      <default>test</default>
      <change>
        <condition label="Test">
          <set token="spacename">cf_space_name="development"</set>
          <set token="time">-60m@m</set>
        </condition>
        <condition label="Prod">
          <set token="spacename">cf_space_name="production"</set>
          <set token="time">@d</set>
        </condition>
      </change>
    </input>
  </fieldset>
0 Karma
1 Solution

jacobpevans
Motivator

Try changing <set token="time"> to <set token="form.time.earliest">. I figured it out by looking at the values in the URL when changing the time directly. You'll also want to change it in your <init> setting. Here's a run-anywhere dashboard:

<form>
  <init>
    <set token="index">test</set>
    <set token="form.time.earliest">-60m@m</set>
  </init>
  <fieldset submitButton="false">
    <input type="time" token="time" searchWhenChanged="true">
      <label>Time Picker</label>
      <default>
        <earliest>-15m</earliest>
        <latest>now</latest>
      </default>
    </input>
    <input type="dropdown" token="index" searchWhenChanged="true">
      <label>Environment</label>
      <choice value="prod">Prod</choice>
      <choice value="test">Test</choice>
      <default>test</default>
      <change>
        <condition label="Test">
          <set token="spacename">cf_space_name="development"</set>
          <set token="form.time.earliest">-60m@m</set>
        </condition>
        <condition label="Prod">
          <set token="spacename">cf_space_name="production"</set>
          <set token="form.time.earliest">@d</set>
        </condition>
      </change>
    </input>
  </fieldset>
  <row>
    <html>
      $time$ --- $form.time.earliest$ --- $spacename$ 
    </html>
  </row>
  <row>
    <panel>
      <event>
        <search>
          <query>index=_internal</query>
          <earliest>$time.earliest$</earliest>
          <latest>$time.latest$</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">50</option>
        <option name="list.drilldown">none</option>
        <option name="list.wrap">1</option>
        <option name="maxLines">5</option>
        <option name="raw.drilldown">full</option>
        <option name="refresh.display">progressbar</option>
        <option name="rowNumbers">0</option>
        <option name="table.drilldown">all</option>
        <option name="table.sortDirection">asc</option>
        <option name="table.wrap">1</option>
        <option name="type">list</option>
      </event>
    </panel>
  </row>
</form>
Cheers,
Jacob

If you feel this response answered your question, please do not forget to mark it as such. If it did not, but you do have the answer, feel free to answer your own post and accept that as the answer.

View solution in original post

jacobpevans
Motivator

Note the typo here: <set token="time"> -60m@m</set> (the space before the '-' sign)

Cheers,
Jacob

If you feel this response answered your question, please do not forget to mark it as such. If it did not, but you do have the answer, feel free to answer your own post and accept that as the answer.

stephenggilmore
Explorer

Thanks for pointing that out! I didn't even notice.

0 Karma

jacobpevans
Motivator

Try changing <set token="time"> to <set token="form.time.earliest">. I figured it out by looking at the values in the URL when changing the time directly. You'll also want to change it in your <init> setting. Here's a run-anywhere dashboard:

<form>
  <init>
    <set token="index">test</set>
    <set token="form.time.earliest">-60m@m</set>
  </init>
  <fieldset submitButton="false">
    <input type="time" token="time" searchWhenChanged="true">
      <label>Time Picker</label>
      <default>
        <earliest>-15m</earliest>
        <latest>now</latest>
      </default>
    </input>
    <input type="dropdown" token="index" searchWhenChanged="true">
      <label>Environment</label>
      <choice value="prod">Prod</choice>
      <choice value="test">Test</choice>
      <default>test</default>
      <change>
        <condition label="Test">
          <set token="spacename">cf_space_name="development"</set>
          <set token="form.time.earliest">-60m@m</set>
        </condition>
        <condition label="Prod">
          <set token="spacename">cf_space_name="production"</set>
          <set token="form.time.earliest">@d</set>
        </condition>
      </change>
    </input>
  </fieldset>
  <row>
    <html>
      $time$ --- $form.time.earliest$ --- $spacename$ 
    </html>
  </row>
  <row>
    <panel>
      <event>
        <search>
          <query>index=_internal</query>
          <earliest>$time.earliest$</earliest>
          <latest>$time.latest$</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">50</option>
        <option name="list.drilldown">none</option>
        <option name="list.wrap">1</option>
        <option name="maxLines">5</option>
        <option name="raw.drilldown">full</option>
        <option name="refresh.display">progressbar</option>
        <option name="rowNumbers">0</option>
        <option name="table.drilldown">all</option>
        <option name="table.sortDirection">asc</option>
        <option name="table.wrap">1</option>
        <option name="type">list</option>
      </event>
    </panel>
  </row>
</form>
Cheers,
Jacob

If you feel this response answered your question, please do not forget to mark it as such. If it did not, but you do have the answer, feel free to answer your own post and accept that as the answer.

stephenggilmore
Explorer

This worked perfectly! Thank you so much!

jacobpevans
Motivator

You're welcome. Thanks for marking the answer!

Cheers,
Jacob

If you feel this response answered your question, please do not forget to mark it as such. If it did not, but you do have the answer, feel free to answer your own post and accept that as the answer.
0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

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 ...