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!

Get ready to show some Splunk Certification swagger at .conf24!

Dive into the deep end of data by earning a Splunk Certification at .conf24. We're enticing you again this ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Now On-Demand Join us to learn more about how you can leverage Service Level Objectives (SLOs) and the new ...

Database Performance Sidebar Panel Now on APM Database Query Performance & Service ...

We’ve streamlined the troubleshooting experience for database-related service issues by adding a database ...