Dashboards & Visualizations

How to set the default value of an input number field to current day's date in Dashboard?

Sharma21
Explorer

I have defined a number.input field in Dashboard Studio (Version:9.0.2) so that the user can select a number representing a date (between 1-31). I want the date to be set to current day's date by default when the user opens the dashboard..

But "defaultValue": "$token_curr_date$" in the code below throws error  - Incorrect Type. Expected "number"

{
    "options": {
        "defaultValue": "$token_curr_date$",
        "token": "num_date",
        "min": 1,
        "max": 31
    },
    "title": "Select Date",
    "type": "input.number"
}
 
In "dataSources" I have defined below search and token:
 
        "ds_current_date": {
            "type": "ds.search",
            "options": {
                "query": "| makeresults | eval token_curr_date=strftime(now(), \"%d\") | fields token_curr_date"
            },
            "token": "token_curr_date"
        }
 
How do set the default value of input.number to current date? 
Labels (2)
0 Karma

Sharma21
Explorer

Not working still. I am thinking that its not even recognizing the token value. Anything wrong with the way I am defining the token or maybe I need to initialize it before it can be referenced?

richgalloway
SplunkTrust
SplunkTrust

The strftime function returns a string rather than an integer expected by defaultValue.  Try converting the string into a number.

...
 "options": {
                "query": "| makeresults | eval token_curr_date=tonumber(strftime(now(), \"%d\")) | fields token_curr_date"
            },
...

 

---
If this reply helps you, Karma would be appreciated.
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...