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!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...