Dashboards & Visualizations

How do I update a time picker value using javascript?

andrewtrobec
Motivator

Hello,

My goal is to use javascript to update the "earliest" value of a time picker input to 6 months ago in the event that the user selects a time range with an "earliest" value greater than 6 months ago.  I don't want a user to be able to extract more than 6 months of data, but at the same time I want them to be able to use the flexibility of the time picker input.

So far I have:

  • Create a token "tok_six_months_ago" under <init> tag on the dashboard which is  set to relative_time(now(),"-6mon@mon")
  • Defined a time picker input with name "tok_data_period"
  • Converted the "tok_data_period" earliest and latest values to epoch via the <change> tag
    • <eval token="tok_earliest_epoch">if(isnum('earliest'),'earliest',relative_time(now(),'earliest')</eval>
    • <eval token="tok_latest_epoch">if(isnum('latest'),'latest',relative_time(now(),'latest')</eval>
  • Created a JavaScript file that monitors changes to "tok_earliest_epoch" and alerts a user when it is out of bounds (it checks earliest against "tok_six_months_ago")
    •     def_tok.on("change:tok_earliest_epoch", function() {
              if(def_tok.get("tok_earliest_epoch") < def_tok.get("tok_six_months_ago")) {
                  alert("Lower time limit is out of bounds: data will only be shown for the last 6 months");
              }
          });

What I would like to do now, but I don't know how, is update the timepicker token on the form (tok_data_period.earliest) with the epoch contained in the "tok_six_months_ago".

Please can somebody help?

Thanks!

Andrew

Labels (3)
Tags (2)
0 Karma
Get Updates on the Splunk Community!

A Prelude to .conf25: Your Guide to Splunk University

Heading to Boston this September for .conf25? Get a jumpstart by arriving a few days early for Splunk ...

4 Ways the Splunk Community Helps You Prepare for .conf25

.conf25 is right around the corner, and whether you’re a first-time attendee or a seasoned Splunker, the ...

Enhance Your Splunk App Development: New Tools & Support

UCC FrameworkAdd-on Builder has been around for quite some time. It helps build Splunk apps faster, but it ...