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!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...