Dashboards & Visualizations

How to set current year in the drop down menu as a default?

YuliyaVassilyev
Explorer

I can do it manually, but prefer to set current year as a default year in my drop down menu. Here is some of source code:

  <label>Year</label>
  <default>2020</default>
Tags (1)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@YuliyaVassilyeva

Can you please try below XML?

<form>
  <label>Default Year</label>
  <search>
    <query>| makeresults | eval current_year = strftime(now(), "%Y")</query>
    <done>
      <set token="current_year">$result.current_year$</set>
    </done>
  </search>
  <fieldset submitButton="false">
    <input type="dropdown" token="field1">
      <label>Year Selection</label>
      <choice value="2019">2019</choice>
      <choice value="2020">2020</choice>
      <choice value="2021">2021</choice>
      <default>$current_year$</default>
    </input>
  </fieldset>
  <row>
    <panel>
      <html>
        Current Year: $current_year$
      </html>
    </panel>
  </row>
</form>

View solution in original post

kamlesh_vaghela
SplunkTrust
SplunkTrust

@YuliyaVassilyeva

Can you please try below XML?

<form>
  <label>Default Year</label>
  <search>
    <query>| makeresults | eval current_year = strftime(now(), "%Y")</query>
    <done>
      <set token="current_year">$result.current_year$</set>
    </done>
  </search>
  <fieldset submitButton="false">
    <input type="dropdown" token="field1">
      <label>Year Selection</label>
      <choice value="2019">2019</choice>
      <choice value="2020">2020</choice>
      <choice value="2021">2021</choice>
      <default>$current_year$</default>
    </input>
  </fieldset>
  <row>
    <panel>
      <html>
        Current Year: $current_year$
      </html>
    </panel>
  </row>
</form>

yvassilyeva
Path Finder

That worked. Thank you!

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

cool @YuliyaVassilyev 

Please accept it for closing the question. 

Thanks

0 Karma

yvassilyeva
Path Finder

@kamlesh_vaghela Your answer works, but there is nowhere here to accept the answer...

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@yvassilyeva 

 

This question raised by YuliyaVassilyev user.  So you have to login with YuliyaVassilyev for accepting. 🙂 

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...