Getting Data In

Set the latest date from search as the default value in dropdown with submit button?

patricianaguit
Explorer

I want to set the latest date from the search as the default value in dropdown, and the submit must be set to true.
Here's my code so far:

  <search>
    <query>index="test_summary_trial" 
|dedup DATE
|eval DATE_ARRANGED1 = strptime(DATE, "%m/%d/%Y")
|sort - ORDER_DATE_ARRANGED1
|stats first(DATE) as DATE_LATEST
      </query>
    <done>
      <set token="currentDate">$result.DATE_LATEST$</set>
    </done>
  </search>
  <fieldset submitButton="true">
    <input type="dropdown" token="date">
      <label> Date</label>
      <fieldForLabel>DATE</fieldForLabel>
      <fieldForValue>DATE</fieldForValue>
      <search>
        <query>index="test_summary_trial" 
|dedup DATE
|eval ORDER_DATE_ARRANGED1 = strptime(DATE, "%m/%d/%Y")
|sort - ORDER_DATE_ARRANGED1
|table DATE</query>
        <earliest>0</earliest>
        <latest></latest>
      </search>
      <default>$currentDate$</default>
    </input>
</fieldset>

The problem is that whenever i set the submitButton to "true", the default value ($currentDate$ token) i set for the Date dropdown isn't working.
Is there a way where I can still set the default value through the token even if the submitButton is set to true?
or
Is there a more efficient way to set the latest date from search as a default value even if the submitButton is set to true?
Thank you for your help in advance 🙂

1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@patricianaguit

Instead of using different search for setting default value can you please try SelectFirstChoice with existing dropdown search?

<selectFirstChoice>true</selectFirstChoice>

eg.

<fieldset submitButton="true">
     <input type="dropdown" token="date">
       <label> Date</label>

       <selectFirstChoice>true</selectFirstChoice>

       <fieldForLabel>DATE</fieldForLabel>
       <fieldForValue>DATE</fieldForValue>
       <search>
         <query>index="test_summary_trial" 
         |dedup DATE
         |eval ORDER_DATE_ARRANGED1 = strptime(DATE, "%m/%d/%Y")
         |sort - ORDER_DATE_ARRANGED1
         |table DATE</query>
         <earliest>0</earliest>
         <latest></latest>
       </search>
     </input>
 </fieldset>

Thanks

View solution in original post

kamlesh_vaghela
SplunkTrust
SplunkTrust

@patricianaguit

Instead of using different search for setting default value can you please try SelectFirstChoice with existing dropdown search?

<selectFirstChoice>true</selectFirstChoice>

eg.

<fieldset submitButton="true">
     <input type="dropdown" token="date">
       <label> Date</label>

       <selectFirstChoice>true</selectFirstChoice>

       <fieldForLabel>DATE</fieldForLabel>
       <fieldForValue>DATE</fieldForValue>
       <search>
         <query>index="test_summary_trial" 
         |dedup DATE
         |eval ORDER_DATE_ARRANGED1 = strptime(DATE, "%m/%d/%Y")
         |sort - ORDER_DATE_ARRANGED1
         |table DATE</query>
         <earliest>0</earliest>
         <latest></latest>
       </search>
     </input>
 </fieldset>

Thanks

patricianaguit
Explorer

thank you 🙂 this worked for me!

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@patricianaguit Glad to help you 🙂

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

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

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...