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!

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...