All Apps and Add-ons

Set pulldown with current month

kmattern
Builder

This should be easy but I'm still missing it. I'm populating a pulldown with the months of the year and their corresponding numbers. Each month, such as April is displayed and the value for that item is "04".

All I want to do is have the pulldown default to the current month and its number when the form is opened. I've tried valueSetter and resultsValueSetter but I must be doing something wrong. My search returns exactly what I want and resultsValueSetter puts the results into the pulldown but, unfortunately, it is at the end of the list and not the selected item.

What am I missing?

somesoni2
Revered Legend

This is how I am doing the same and it works.

<view autoCancelInterval="90" isPersistable="true" isSticky="true" isVisible="true" objectMode="SimpleForm" onunloadCancelJobs="true" template="dashboard.html">
  <label>Pulldown with current Month</label>

  <module name="AccountBar" layoutPanel="appHeader"/>
  <module name="AppBar" layoutPanel="navigationHeader"/>
  <module name="SideviewUtils" layoutPanel="appHeader"/>
  <!-- End Application Header -->


  <!-- Start URL Loader -->
  <module name="URLLoader" layoutPanel="viewHeader" autoRun="True">

    <!-- Start Search month pulldown -->
    <module name="Search">
      <param name="search">
        | stats count | eval varMonth=if(""=="$varMonth$",lower(strftime(now(),"%m")),"$varMonth$")
        | table varMonth
      </param>

      <!-- Start Set result value from current date time search -->
      <module name="ResultsValueSetter">
        <param name="fields">varMonth</param>
        <!-- Start Pulldown - Months -->
        <module name="Pulldown" layoutPanel="viewHeader">
          <param name="name">varMonth</param>
          <param name="label">Month:</param>
          <param name="staticFieldsToDisplay">
            <list>
              <param name="value">01</param>
              <param name="label">January</param>
            </list>
            <list>
              <param name="value">02</param>
              <param name="label">February</param>
            </list>
            <list>
              <param name="value">03</param>
              <param name="label">March</param>
            </list>
            <list>
              <param name="value">04</param>
              <param name="label">April</param>
            </list>
            <list>
              <param name="value">05</param>
              <param name="label">May</param>
            </list>
            <list>
              <param name="value">06</param>
              <param name="label">June</param>
            </list>
            <list>
              <param name="value">07</param>
              <param name="label">July</param>
            </list>
            <list>
              <param name="value">08</param>
              <param name="label">August</param>
            </list>
            <list>
              <param name="value">09</param>
              <param name="label">September</param>
            </list>
            <list>
              <param name="value">10</param>
              <param name="label">October</param>
            </list>
            <list>
              <param name="value">11</param>
              <param name="label">November</param>
            </list>
            <list>
              <param name="value">12</param>
              <param name="label">December</param>
            </list>
          </param>
          <module name="HTML"  layoutPanel="viewHeader">
            <param name="html">
              <![CDATA[  
       <table cellpadding="0" cellspacing="0" style="width: 100%">
        <tr>
            <td width="15%" align="left">
                <h2> Selected Month: $varMonth$</h2>
            </td>            
        </tr>
    </table> ]]>
            </param>
          </module>
        </module>
        <!--Pulldown-->
        <!-- End Pulldown - Months -->
      </module>
      <!--ResultsValueSetter-->
      <!-- End Set result value from current hour search -->
    </module>
    <!--Search-->
    <!-- End Search current year,month,day for year,month,day,hour pulldown -->
  </module>
  <!--URLLoader-->
  <!-- End URL Loader -->
</view>

sideview
SplunkTrust
SplunkTrust

Cool solution. I think your search language is working to avoid clobbering a ?varMonth=02 that might be present up in the URL, and that might be prepopulating the Pulldown sometimes via the URLLoader module.

That search language trick seems to work well but you might read up about ValueSetter's "allowClobber" param, which defaults to true but can be set to False for when you want a value to appear only when something else upstream hasn't set it.... You'd still need the Search to turn now() into the month, but ResultsValueSetter + ValueSetter could dispense with all the if() logic.

Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

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 ...