Dashboards & Visualizations

Is there a Form Element that will accept a single datetime value?

Ashwin3
Engager

Is there a form element that accepts only a single datetime value?

User will be entering two fields, field 1 as  a single datetime and field 2 as a duration like "1h".

Based on this two inputs, need to calculate and set time values as below

 

For eg:

User input field 1[TimeTokenMid] --> 07/12/2022:18:00:00

User input field 2[Duration] --> "1h"

Need to calculate and set time ranges as below using relative_time function.

Token_1 = 07/12/2022:17:00:00 [TimeTokenMid - Duration using relative_time fnc]

Token_2 = 07/12/2022:19:00:00 [TimeTokenMid + Duration using relative_time fnc]

Currently i am taking field 1[TimeTokenMid] as text and doing calculation as the current timepicker control is not allowing to set a single custom time value. It has options only for selecting a range like (last 60 mins, between x and y etc)like that. In my usecase,I want to take a single timevalue input and calculate time ranges(+-) based on the duration input dynamically. Could you please suggest any solution?

Labels (1)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

One way is to use <eval token /> under <progress /> with a fake search, as inspired by .

For example,

<form>
  <label>Set time window</label>
  <search>
    <query>
      | makeresults
    </query>
    <progress>
      <condition match="true()">
        <eval token="latest_tok">strftime(relative_time(strptime($Token_1$, "%m/%d/%Y:%H:%M:%S"), "+" . $Token_2$), "%m/%d/%Y:%H:%M:%S")</eval>
      </condition>
    </progress>
  </search>
  <fieldset submitButton="false">
    <input type="dropdown" token="Token_1" searchWhenChanged="true">
      <label>start time</label>
      <choice value="07/12/2022:17:00:00">07/12/2022:17:00:00</choice>
      <choice value="07/13/2022:17:00:00">07/13/2022:17:00:00</choice>
      <choice value="07/14/2022:17:00:00">07/14/2022:17:00:00</choice>
      <initialValue>07/12/2022:17:00:00</initialValue>
    </input>
    <input type="dropdown" token="Token_2" searchWhenChanged="true">
      <label>interval</label>
      <choice value="2h">2h</choice>
      <choice value="4h">4h</choice>
      <choice value="8h">8h</choice>
      <choice value="12h">12h</choice>
      <default>2h</default>
    </input>
  </fieldset>
  <row>
    <panel>
      <html>
        <div>latest token: $latest_tok$</div>
      </html>
    </panel>
  </row>
</form>

 

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...