Dashboards & Visualizations

Token not getting set on default value of input dropdown

njohnson7
Path Finder

On Dashboard load, when my initial value/default value is daily my token  <set token="tok_daily">$dailytoken$</set> is not set (not getting today's date automatically) where as this( <set token="tok_weekly">*</set>,) is set.   I have to change the dropdown to weekly and change it back to daily again for it to work properly. Can someone tell what am I doing wrong ?

 

<search>
<query>
| makeresults | eval today=strftime(now()+19800, "%m/%d/%Y") , currentweek=strftime(now()+19800, "%U-%Y") | table today currentweek
</query>
<done>
<set token="dailytoken">$result.today$</set>
<set token="weeklytoken">$result.currentweek$</set>
</done>
</search>
<fieldset submitButton="false" autorun="true">
<input type="dropdown" token="custom_time_token" searchWhenChanged="true">
<label>Select Time Range</label>
<choice value="daily">Daily</choice>
<choice value="weekly">Weekly</choice>
<choice value="monthly">Monthly</choice>
<initialValue>daily</initialValue>

<default>daily<default>

<change>
<condition value="daily">
<set token="tok_daily">$dailytoken$</set>
<set token="tok_weekly">*</set>
</condition>
<condition value="weekly">
<set token="tok_weekly">$weeklytoken$</set>
<set token="tok_daily">*</set>
</condition>
</change>
</input>
</fieldset>

 

 

 

basesearchstring | search scheduled_delivery_date ="$tok_daily$" AND week_of_year="$tok_weekly$" AND delivery_month="$tok_monthly$"

 

 

When I used those set token values in my base search  my result is like this 

 

 

basesearchstring | search scheduled_delivery_date ="$tok_daily$" AND week_of_year=* AND delivery_month=*

 

 

Labels (1)
Tags (1)
0 Karma
1 Solution

njohnson7
Path Finder

This worked . Thanks to @Kompaan 

 <init>
    <eval token="tok_daily">strftime(now()+19800, "%m/%d/%Y")</eval>
  </init>

View solution in original post

0 Karma

spitchika
Path Finder

Yes, it will not set because you are validating "Daily" only on change event...

Instead do like below in "Init" tags itself. This works for your scenario.

If you are using form then include after <form> and same case with <dashboard> tag as well.

<form>
<init>
<set token="tok_daily">$dailytoken$</set>
<set token="tok_weekly">$weeklytoken$</set>
</init>

 

0 Karma

njohnson7
Path Finder

@spitchika yea I am aware of the init tags. 

But like I said, the tok_weekly is automatically getting "*" , as in it is getting set and just that the tok_daily is not. 

I am just wondering how that's happening ? 

 

0 Karma

njohnson7
Path Finder

I tried this , still not working though 😞 

<form >
  <label>Dashboard Name</label>
  <init>
    <set token="tok_daily">$dailytoken$</set>
  </init>
  <search>
    <query>
      | makeresults | eval today=strftime(now()+19800, "%m/%d/%Y") ,  currentweek=strftime(now()+19800, "%U-%Y") , currentmonth=strftime(now()+19800, "%b-%Y") | table today currentweek currentmonth
    </query>
    <done>
      <set token="dailytoken">$result.today$</set>
      <set token="weeklytoken">$result.currentweek$</set>
      <set token="monthtoken">$result.currentmonth$</set>
    </done>
  </search>
  <search id="basequery">
    <query>
searchterms | search scheduled_delivery_date="$tok_daily$" AND week_of_year="$tok_weekly$" AND delivery_month="$tok_monthly$"
  </query>
    <earliest>-1mon@mon</earliest>
    <latest>now</latest>
  </search>
<fieldset submitButton="false" autoRun="true">
    <input type="dropdown" token="custom_time_token" searchWhenChanged="true">
      <label>Select View</label>
      <choice value="dailytok">Daily</choice>
      <choice value="weekly">Weekly</choice>
      <choice value="monthly">Monthly</choice>
      <change>
        <condition value="dailytok">
          <set token="tok_daily">$dailytoken$</set>
          <set token="tok_weekly">*</set>
          <set token="tok_monthly">*</set>
          <set token="chartpaneldaily">true</set>
          <unset token="chartpanelweekly"></unset>
          <unset token="chartpanelmonthly"></unset>
        </condition>
        <condition value="weekly">
          <set token="tok_weekly">$weeklytoken$</set>
          <set token="tok_daily">*</set>
          <set token="tok_monthly">*</set>
          <unset token="chartpaneldaily"></unset>
          <set token="chartpanelweekly">true</set>
          <unset token="chartpanelmonthly"></unset>
        </condition>
        <condition value="monthly">
          <set token="tok_monthly">$monthtoken$</set>
          <set token="tok_daily">*</set>
          <set token="tok_weekly">*</set>
          <unset token="chartpaneldaily"></unset>
          <unset token="chartpanelweekly">true</unset>
          <set token="chartpanelmonthly"></set>
        </condition>
      </change>
      <default>dailytok</default>
      <initialValue>dailytok</initialValue>
    </input>
  </fieldset>

 

0 Karma

spitchika
Path Finder

Try this It works perfectly for me...

<form>
<label>Dummy</label>
<init>
<set token="custom_time_token">$dailytoken$</set>
<unset token="daily_enable"></unset>
<unset token="weekly_enable"></unset>
<unset token="monthly_enable"></unset>
</init>
<search>
<query>
| makeresults | eval today=strftime(now()+19800, "%m/%d/%Y") , currentweek=strftime(now()+19800, "%U-%Y") , currentmonth=strftime(now()+19800, "%b-%Y") | table today currentweek currentmonth
</query>
<done>
<set token="dailytoken">$result.today$</set>
<set token="weeklytoken">$result.currentweek$</set>
<set token="monthtoken">$result.currentmonth$</set>
</done>
</search>
<search id="basequery">
<query>
searchterms | search scheduled_delivery_date="$tok_daily$" AND week_of_year="$tok_weekly$" AND delivery_month="$tok_monthly$"
</query>
<earliest>-1mon@mon</earliest>
<latest>now</latest>
</search>
<fieldset submitButton="false" autoRun="true">
<input type="dropdown" token="custom_time_token" searchWhenChanged="true">
<label>Select View</label>
<choice value="dailytok">Daily</choice>
<choice value="weekly">Weekly</choice>
<choice value="monthly">Monthly</choice>
<change>
<condition value="dailytok">
<set token="tok_daily">$dailytoken$</set>
<set token="daily_enable"></set>
<unset token="monthly_enable"></unset>
<unset token="weekly_enable"></unset>
</condition>
<condition value="weekly">
<set token="tok_weekly">$weeklytoken$</set>
<set token="weekly_enable"></set>
<unset token="daily_enable"></unset>
<unset token="monthly_enable"></unset>
</condition>
<condition value="monthly">
<set token="tok_monthly">$monthtoken$</set>
<set token="monthly_enable"></set>
<unset token="daily_enable"></unset>
<unset token="weekly_enable"></unset>
</condition>
</change>
<default>dailytok</default>
<initialValue>dailytok</initialValue>
</input>
</fieldset>
<row>
<panel depends="$weekly_enable$">
<html>
<div>Hello_Its Weekly</div>
</html>
</panel>
<panel depends="$daily_enable$">
<html>
<div>Hello_Its Daily</div>
</html>
</panel>
<panel depends="$monthly_enable$">
<html>
<div>Hello_Its Monthly</div>
</html>
</panel>
</row>
</form>

0 Karma

njohnson7
Path Finder

This worked . Thanks to @Kompaan 

 <init>
    <eval token="tok_daily">strftime(now()+19800, "%m/%d/%Y")</eval>
  </init>
0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...