Dashboards & Visualizations

How to dynamically change time period of search and results in dashboard

technie101
Explorer

My Splunk dashboard contains a timepicker along with a search results panel which displays a table output. The dashboard can be accessed by passing a input parameter 'form.queryParam.earliest' from another dashboard. Or it can directly be accessed independently without passing a parameter.

The expected behavior is:

  • If accessed with the input parameter, on loading, the results should be shown based on query param passed.
    • Now, if the value of the timepicker is changed, it should refresh the search and update the results.
  • If accessed without the input parameter, the results should be shown based on the default value of the time picker.
    • Now, if the timepicker value is changed, it should refresh the search and update the results.

With this in mind, I configured it with the following.

<form>
  <label>Test Dashboard</label>
  <fieldset submitButton="false" autoRun="true">
    <input type="time" token="selectedTimestamp" searchWhenChanged="true">
      <label>Time</label>
      <default>
        <earliest>-1d@d</earliest>
        <latest></latest>
      </default>
      <change>
        <set token="timeChanged">true</set>
      </change>
    </input>
  </fieldset>
  <!-- DUMMY SEARCH TO EVALUATE FINAL VALUE BASED ON CONDITIONS --> 
  <search>
    <query>| makeresults</query>
    <earliest>-1s@s</earliest>
    <latest>now</latest>
    <done>
      <eval token="finalEarliest">case(isnotnull($timeChanged$), $form.selectedTimestamp.earliest$, isnotnull($form.queryParam.earliest$), $form.queryParam.earliest$, true(), $form.selectedTimestamp.earliest$)</eval>
    </done>
  </search>
  <!-- ACTUAL SEARCH --> 
  <row>
    <panel>
      <title>Results Tale</title>
      <table>
        <search>
          <query>ACTUAL QUERY</query>
          <earliest>$finalEarliest$</earliest>
          <latest>now</latest>
        </search>
        <option name="link.exportResults.visible">0</option>
        <option name="link.inspectSearch.visible">0</option>
        <option name="link.openPivot.visible">0</option>
        <option name="link.openSearch.visible">0</option>
        <option name="refresh.link.visible">0</option>
        <format type="color" field="percent_of_total_count">
          <colorPalette type="list">[#65A637,#6DB7C6,#F7BC38,#F58F39,#D93F3C]</colorPalette>
          <scale type="threshold">0,30,70,100</scale>
        </format>
      </table>
    </panel>
  </row>
</form>

I am having 2 problems with this.

  1. The timeChanged value always returns true because of which the dashboard always loads with the default value of the timepicker even when the input parameter is passed in the url.
  2. The search results don't get refreshed when the timepicker value is changed in the dropdown.

Can someone please help.

Regards.

0 Karma

maciep
Champion

Seem like you may be over complicating this a bit? Why not just pass the actual timepicker values in the URL from the other dashboard? Something like this?

form.selectedTimestamp.earliest=-5d&form.selectedTimestamp.latest=now

And just set your search to use the timepicker's values?

       <earliest>$selectedTimestamp.earliest$</earliest>
       <latest>$selectedTimestamp.latest$</latest>

technie101
Explorer

Thanks maciep for the reply.

This helps. Although, one scenario is still open. The child dashboard can also be accessed directly, in which case I want to set defaults for the earliest and latest values of the timepicker. Can you please suggest?

Thanks

0 Karma

maciep
Champion

what part of that doesn't work currently? The timepicker in the child dashboard would have the default range configured, right? So if you go there manually, without populating anything in the url, then it should use those defaults.

0 Karma
Get Updates on the Splunk Community!

.conf25 Community Recap

Hello Splunkers, And just like that, .conf25 is in the books! What an incredible few days — full of learning, ...

Splunk App Developers | .conf25 Recap & What’s Next

If you stopped by the Builder Bar at .conf25 this year, thank you! The retro tech beer garden vibes were ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...