Dashboards & Visualizations

How can I get the current time in HH:MM:SS as the default value in dropdown?

pradeepkumarg
Influencer

I have a drop down where the user can select the Time as below.

<choice value="00:00:00">00:00:00</choice>
<choice value="01:00:00">01:00:00</choice>
<choice value="02:00:00">02:00:00</choice>
<choice value="03:00:00">03:00:00</choice>
<choice value="04:00:00">04:00:00</choice>
<choice value="05:00:00">05:00:00</choice>
<choice value="06:00:00">06:00:00</choice>
<choice value="07:00:00">07:00:00</choice>
<choice value="08:00:00">08:00:00</choice>
<choice value="09:00:00">09:00:00</choice>
.
.
.
&ltchoice value="24:00:00">24:00:00</choice>

Now, I want to provide a default value which will be current time.

I think I can pass a dummy value like below


<choice value="abc">Current Time</choice>

and then handle it in my search to check for that dummy value and replace it with now() to get the time.

But wanted to check if there is a better way to do this

Tags (3)
1 Solution

strive
Influencer

Add this inside your fieldset

<input type="dropdown" token="varHours" id="field1">       
  <label>Hours :</label>
    <populatingSearch fieldForValue="hours" fieldForLabel="value">
        <![CDATA[search * | head 1 | eval tnow = now() | eval hours = strftime(tnow, "%H:%M:%S") | eval value="Current Time" | table value hours | append [| gentimes start=-1 end=0 increment=1h | eval hours = strftime(starttime, "%H:%M:%S") | eval value=hours | table value hours]]]>
    </populatingSearch>
</input>

alt text

View solution in original post

strive
Influencer

Add this inside your fieldset

<input type="dropdown" token="varHours" id="field1">       
  <label>Hours :</label>
    <populatingSearch fieldForValue="hours" fieldForLabel="value">
        <![CDATA[search * | head 1 | eval tnow = now() | eval hours = strftime(tnow, "%H:%M:%S") | eval value="Current Time" | table value hours | append [| gentimes start=-1 end=0 increment=1h | eval hours = strftime(starttime, "%H:%M:%S") | eval value=hours | table value hours]]]>
    </populatingSearch>
</input>

alt text

pradeepkumarg
Influencer

Awesome.. Thank you..

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

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