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
Get Updates on the Splunk Community!

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...

Brains, Bytes, and Boston: Learn from the Best at .conf25

When you think of Boston, you might picture colonial charm, world-class universities, or even the crack of a ...