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!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...