Dashboards & Visualizations

In the dropdown Input how can I select the second Value of a list?

marziaolla
Path Finder

Hello there,
I need to set as a default always the second element of my list values, the value can change but I need to take always the second one.

How can I make that?
There's a way with javascript?

Thank you.

Marzia.

0 Karma

niketn
Legend

@marziaolla, Try the following Run anywhere dashboard example. It uses post-processing to identify the second value in the dropdown and sets the same as a token for default value.

PS: If the search for Dropdown returns only one result, the same will be set as default value. Also in case the Search does not return any results, I have used Static All option to be set as default value.

alt text

<form>
  <label>Second Value in the list</label>
 <!-- Your Search to populate the second item from the list should go here --->
  <search base="baseComponentSearch">
    <query>| head 2 | tail 1
    </query>
    <done>
      <!-- In case the Search does not return any results Static Option All should be selected -->
      <condition match="$job.resultCount$==0">
        <set token="tokDefaultSelectedComponent">*</set>
      </condition>
      <!-- Set the token using Search Event Handler's default token result.<yourFieldName> -->
      <!-- If the Search returns two or more results 2nd result will be selected -->
      <!-- If the Search returns only one result, the same will be selected -->
      <condition>
        <set token="tokDefaultSelectedComponent">$result.component$</set>
      </condition>
    </done>
  </search>
  <fieldset submitButton="false">
    <input type="time" token="tokTime" searchWhenChanged="true">
      <label></label>
      <default>
        <earliest>-7d@h</earliest>
        <latest>now</latest>
      </default>
    </input>
    <input type="dropdown" token="tokComponent" searchWhenChanged="true">
      <label>Select Component</label>
      <fieldForLabel>component</fieldForLabel>
      <fieldForValue>component</fieldForValue>
      <search id="baseComponentSearch">
        <query>index=_internal sourcetype=splunkd log_level!="INFO" earliest="$tokTime.earliest$" latest="$tokTime.latest$"
| stats count by component
| sort - count
| head 5</query>
        <earliest>-24h@h</earliest>
        <latest>now</latest>
      </search>
      <choice value="*">All</choice>
      <default>$tokDefaultSelectedComponent$</default>
    </input>
  </fieldset>
  <row>
    <panel>
      <chart>
        <search>
          <query>index=_internal sourcetype=splunkd log_level!=INFO component="$tokComponent$"
| timechart count by component</query>
          <earliest>$tokTime.earliest$</earliest>
          <latest>$tokTime.latest$</latest>
        </search>
        <option name="charting.chart">line</option>
        <option name="charting.drilldown">all</option>
        <option name="refresh.display">progressbar</option>
      </chart>
    </panel>
  </row>
</form>
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

somesoni2
SplunkTrust
SplunkTrust

Any specific reason for it? Can you move the 2nd element in the first position (at populating search level) and then set the first element (which was 2nd element before) as default?

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In the last month, the Splunk Threat Research Team (STRT) has had 2 releases of new security content via the ...

Announcing the 1st Round Champion’s Tribute Winners of the Great Resilience Quest

We are happy to announce the 20 lucky questers who are selected to be the first round of Champion's Tribute ...

We’ve Got Education Validation!

Are you feeling it? All the career-boosting benefits of up-skilling with Splunk? It’s not just a feeling, it's ...