<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to implement a logic when the page is loaded? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-to-implement-a-logic-when-the-page-is-loaded/m-p/452344#M8203</link>
    <description>&lt;P&gt;How to implement a logic when the page is loaded&lt;BR /&gt;
When the page is loaded, the drop-down box displays the last month of the month by default.&lt;BR /&gt;
Now, if it's August, the drop-down box will display 201807 by default.&lt;BR /&gt;
Now, if it's September, the drop-down box will display 201808 by default, and so on.&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5740i7A221241764E2912/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;code xml&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5741i9C436210C3A0D31B/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 08 Sep 2018 05:40:37 GMT</pubDate>
    <dc:creator>flzhang132</dc:creator>
    <dc:date>2018-09-08T05:40:37Z</dc:date>
    <item>
      <title>How to implement a logic when the page is loaded?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-implement-a-logic-when-the-page-is-loaded/m-p/452344#M8203</link>
      <description>&lt;P&gt;How to implement a logic when the page is loaded&lt;BR /&gt;
When the page is loaded, the drop-down box displays the last month of the month by default.&lt;BR /&gt;
Now, if it's August, the drop-down box will display 201807 by default.&lt;BR /&gt;
Now, if it's September, the drop-down box will display 201808 by default, and so on.&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5740i7A221241764E2912/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;code xml&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5741i9C436210C3A0D31B/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Sep 2018 05:40:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-implement-a-logic-when-the-page-is-loaded/m-p/452344#M8203</guid>
      <dc:creator>flzhang132</dc:creator>
      <dc:date>2018-09-08T05:40:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to implement a logic when the page is loaded?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-implement-a-logic-when-the-page-is-loaded/m-p/452345#M8204</link>
      <description>&lt;P&gt;@flzhang132,&lt;/P&gt;

&lt;P&gt;Just add a page load token using &lt;CODE&gt;init&lt;/CODE&gt; and set &lt;CODE&gt;default&lt;/CODE&gt; and &lt;CODE&gt;initialValue&lt;/CODE&gt; to that&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form&amp;gt;
  &amp;lt;init&amp;gt;
    &amp;lt;eval token="prev_month"&amp;gt;strftime(relative_time(now(),"-1mon"),"%Y%m")&amp;lt;/eval&amp;gt;
  &amp;lt;/init&amp;gt;
  &amp;lt;fieldset submitButton="false"&amp;gt;
    &amp;lt;input type="dropdown" token="ymmon"&amp;gt;
      &amp;lt;label&amp;gt;Date&amp;lt;/label&amp;gt;
      &amp;lt;choice value="ym201801"&amp;gt;201801&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="ym201802"&amp;gt;201802&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="ym201803"&amp;gt;201803&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="ym201804"&amp;gt;201804&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="ym201805"&amp;gt;201805&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="ym201806"&amp;gt;201806&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="ym201807"&amp;gt;201807&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="ym201808"&amp;gt;201808&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="ym201809"&amp;gt;201809&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="ym201810"&amp;gt;201810&amp;lt;/choice&amp;gt;
      &amp;lt;default&amp;gt;$prev_month$&amp;lt;/default&amp;gt;
      &amp;lt;initialValue&amp;gt;$prev_month$&amp;lt;/initialValue&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Sep 2018 11:13:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-implement-a-logic-when-the-page-is-loaded/m-p/452345#M8204</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-09-08T11:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to implement a logic when the page is loaded?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-implement-a-logic-when-the-page-is-loaded/m-p/452346#M8205</link>
      <description>&lt;P&gt;@flzhang132 &lt;CODE&gt;&amp;lt;init&amp;gt;&lt;/CODE&gt; section is available post &lt;CODE&gt;Splunk Enterprise 6.5&lt;/CODE&gt; which works only with Simple XML Dashboards, so documenting a workaround of using independent search with search event handler. (PS: prior to Splunk Enterprise 6.5 they were &lt;CODE&gt;&amp;lt;preview&amp;gt;&lt;/CODE&gt; and &lt;CODE&gt;&amp;lt;finalized&amp;gt;&lt;/CODE&gt; instead of &lt;CODE&gt;&amp;lt;progress&amp;gt;&lt;/CODE&gt; and &lt;CODE&gt;&amp;lt;done&amp;gt;&lt;/CODE&gt; from 6.5 onward).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;search&amp;gt;
    &amp;lt;query&amp;gt;| makeresults
| eval prev_month=strftime(relative_time(now(),"-1mon@mon"),"%Y%m")      
    &amp;lt;/query&amp;gt;
    &amp;lt;done&amp;gt;
      &amp;lt;set token="prev_month"&amp;gt;$result.prev_month$&amp;lt;/set&amp;gt;
    &amp;lt;/done&amp;gt;
  &amp;lt;/search&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please refer to using &lt;CODE&gt;&amp;lt;eval&amp;gt;&lt;/CODE&gt; to set token using &lt;CODE&gt;relative_time()&lt;/CODE&gt; will use Client Time Zone: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Viz/tokens#Define_token_filtering_and_formatting"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Viz/tokens#Define_token_filtering_and_formatting&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;1) With independent &lt;CODE&gt;&amp;lt;search&amp;gt;&lt;/CODE&gt; you should be able to perform complicated searches to fetch result to set required token.&lt;BR /&gt;
2) You should also add &lt;CODE&gt;depends&lt;/CODE&gt; attribute with the default value token to the &lt;CODE&gt;&amp;lt;input&amp;gt;&lt;/CODE&gt; to ensure that it is displayed only when the default value is set.&lt;/P&gt;

&lt;P&gt;Following is a run anywhere example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form&amp;gt;
  &amp;lt;label&amp;gt;Initialize form variables on load&amp;lt;/label&amp;gt;
  &amp;lt;search&amp;gt;
    &amp;lt;query&amp;gt;| makeresults
| eval prev_month=strftime(relative_time(now(),"-1mon@mon"),"%Y%m")      
    &amp;lt;/query&amp;gt;
    &amp;lt;done&amp;gt;
      &amp;lt;set token="prev_month"&amp;gt;$result.prev_month$&amp;lt;/set&amp;gt;
    &amp;lt;/done&amp;gt;
  &amp;lt;/search&amp;gt;
   &amp;lt;fieldset submitButton="false"&amp;gt;
     &amp;lt;input type="dropdown" token="ymmon" depends="$prev_month$"&amp;gt;
       &amp;lt;label&amp;gt;Date&amp;lt;/label&amp;gt;
       &amp;lt;choice value="ym201801"&amp;gt;201801&amp;lt;/choice&amp;gt;
       &amp;lt;choice value="ym201802"&amp;gt;201802&amp;lt;/choice&amp;gt;
       &amp;lt;choice value="ym201803"&amp;gt;201803&amp;lt;/choice&amp;gt;
       &amp;lt;choice value="ym201804"&amp;gt;201804&amp;lt;/choice&amp;gt;
       &amp;lt;choice value="ym201805"&amp;gt;201805&amp;lt;/choice&amp;gt;
       &amp;lt;choice value="ym201806"&amp;gt;201806&amp;lt;/choice&amp;gt;
       &amp;lt;choice value="ym201807"&amp;gt;201807&amp;lt;/choice&amp;gt;
       &amp;lt;choice value="ym201808"&amp;gt;201808&amp;lt;/choice&amp;gt;
       &amp;lt;choice value="ym201809"&amp;gt;201809&amp;lt;/choice&amp;gt;
       &amp;lt;choice value="ym201810"&amp;gt;201810&amp;lt;/choice&amp;gt;
       &amp;lt;default&amp;gt;$prev_month$&amp;lt;/default&amp;gt;
       &amp;lt;initialValue&amp;gt;$prev_month$&amp;lt;/initialValue&amp;gt;
     &amp;lt;/input&amp;gt;
   &amp;lt;/fieldset&amp;gt;
   &amp;lt;row&amp;gt;
     &amp;lt;panel&amp;gt;
       &amp;lt;html&amp;gt;
         &amp;lt;div&amp;gt;prev_month: $prev_month$&amp;lt;/div&amp;gt;
       &amp;lt;/html&amp;gt;
     &amp;lt;/panel&amp;gt;
   &amp;lt;/row&amp;gt;
 &amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Sep 2018 17:13:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-implement-a-logic-when-the-page-is-loaded/m-p/452346#M8205</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-09-08T17:13:53Z</dc:date>
    </item>
  </channel>
</rss>

