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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...