Dashboards & Visualizations

Setting token for a dropdwn with a search and init

fabrizioalleva
Path Finder

Hello,
I'm trying from an initial search to put the value into a token to use it as a default initial value for a dropdown list something like this:

<form script="table_with_buttons.js">
      <search>
        <query>
            | makeresults
            | eval day=strftime(now(), "%d")
            | fields day  
        </query>
        <done>
          <set token="day">$result.day$</set>
        </done>
      </search>
      <init>
        <set token="start_day">$day$</set>
       </init>
  <row>
    <panel>
      <title>Data Inizio</title>
      <input type="dropdown" token="start_day">
        <label>Giorno $start_day$</label>
        <fieldForLabel>giorno</fieldForLabel>
        <fieldForValue>giornoid</fieldForValue>
        <search>
          <query>|inputlookup day.csv| table dayid day</query>
        </search>
        <choice value="$start_day$">$start_day$</choice>
        <default>$start_day$</default>
      </input>
    </panel>
  </row>
<form>

at runtime what I obtain is shown in the picture :

alt text

Any Suggestion ?
Thanks
Fabrizio

Tags (3)
0 Karma
1 Solution

vnravikumar
Champion

Hi

Check this, Please correct fieldForLabel and fieldForValue based on your query

<form script="table_with_buttons.js">
  <search>
    <query>
             | makeresults
             | eval day=strftime(now(), "%d")
             | fields day  
         </query>
    <done>
      <set token="day">$result.day$</set>
    </done>
  </search>
  <init>
    <set token="start_day">$day$</set>
  </init>
  <fieldset submitButton="false"></fieldset>
  <row>
    <panel>
      <title>Data Inizio</title>
      <input type="dropdown" token="start_day">
        <label>Giorno $start_day$</label>
        <fieldForLabel>day</fieldForLabel>
        <fieldForValue>day</fieldForValue>
        <search>
          <query>| makeresults count=31 | streamstats count as day</query>
        </search>
        <default>$start_day$</default>
      </input>
    </panel>
  </row>
</form>

View solution in original post

0 Karma

vnravikumar
Champion

Hi

Check this, Please correct fieldForLabel and fieldForValue based on your query

<form script="table_with_buttons.js">
  <search>
    <query>
             | makeresults
             | eval day=strftime(now(), "%d")
             | fields day  
         </query>
    <done>
      <set token="day">$result.day$</set>
    </done>
  </search>
  <init>
    <set token="start_day">$day$</set>
  </init>
  <fieldset submitButton="false"></fieldset>
  <row>
    <panel>
      <title>Data Inizio</title>
      <input type="dropdown" token="start_day">
        <label>Giorno $start_day$</label>
        <fieldForLabel>day</fieldForLabel>
        <fieldForValue>day</fieldForValue>
        <search>
          <query>| makeresults count=31 | streamstats count as day</query>
        </search>
        <default>$start_day$</default>
      </input>
    </panel>
  </row>
</form>
0 Karma

fabrizioalleva
Path Finder

It doesn't work in the dropdown the default value is not 15 ( today ) is always $day$.
It seems that Splunk doesn't accept the first query which pass the today value in the token.
The porpouse is to load a dropdown with the list of days, and by default to show the today value.

Thanks

0 Karma

vnravikumar
Champion

Can you try this

<form script="table_with_buttons.js">
  <search>
    <query>
             | makeresults
             | eval day=strftime(now(), "%d")
             | fields day  
         </query>
    <done>
      <set token="day">$result.day$</set>
    </done>
  </search>
  <fieldset submitButton="false"></fieldset>
  <row>
    <panel>
      <title>Data Inizio</title>
      <input type="dropdown" token="start_day">
        <label>Giorno $day$</label>
        <fieldForLabel>day</fieldForLabel>
        <fieldForValue>day</fieldForValue>
        <search>
          <query>| makeresults count=31 | streamstats count as day</query>
        </search>
        <default>$day$</default>
      </input>
    </panel>
  </row>
</form>
0 Karma

fabrizioalleva
Path Finder

Ok this works fine !
Thanks a lot!
How can I accept this as ansswer ??

0 Karma

vnravikumar
Champion

please click accept button

0 Karma
Get Updates on the Splunk Community!

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

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...