All Apps and Add-ons

Populate staticOptions label and name with ValueSetter tokens

redc
Builder

I'm doing some highly-templated work with views and prefer to be able to set any static variables (the kind that change from view to view, but are otherwise used the same in the rest of the XML) near the top of the code so that you only have to change them in one place rather than scan through the entire XML document and hope you find them all.

I have a scenario where I'm populating a Pulldown with a search, but I don't want the default "Default" label and "*" value. I'd like to be able to specify a given label and value for the default option, but the contents of those would change depending on which view you're loading. To that end, I created a couple of ValueSetter modules near the top of my XML and then tried using $foo$ tokens in the label/value list params in the staticOptions param. Suffice to say, staticOptions doesn't currently support $foo$ tokens there.

Here's the code I've got, I'm looking for a workaround that will let me keep the static variables at the top:

<view autoCancelInterval="90" isVisible="true" objectMode="SimpleForm" onunloadCancelJobs="true" template="dashboard.html" stylesheet="application.css" script="application.js">
  <label>Home</label>
  <module name="AccountBar" layoutPanel="appHeader"/>
  <module name="AppBar" layoutPanel="navigationHeader"/>
  <module name="SideviewUtils" layoutPanel="appHeader" />
  <module name="URLLoader" layoutPanel="viewHeader" autoRun="True">
    <!--Set static variables for later use-->
    <!-- Description for default site to display on page load -->
    <module name="ValueSetter">
      <param name="name">defaultLabel</param>
      <param name="value">MyDefaultSite</param>
      <!-- selectedWebsite abbr for default site to display on page load -->
      <module name="ValueSetter">
        <param name="name">defaultValue</param>
        <param name="value">MDS</param>
          <module name="Search">
            <param name="search">...  | table Description, Abbr</param>
            <module name="Pulldown">
              <param name="name">selectedWebsite</param>
              <param name="label">Web Site: </param>
              <param name="staticOptions">
                <!-- Set default website to display when page loads -->
                <list>
                  <param name="label">$defaultLabel$</param>
                  <param name="value">$defaultValue$</param>
                </list>
              </param>
              <param name="labelField">Description</param>
              <param name="valueField">Abbr</param>

For the curious, a couple of things I tried before finding this post that states that staticOptions doesn't currently support $foo$ tokens:

  • $$defaultLabel$$ and $$defaultValue$$
  • Adding CDATA tags to the label and value params in staticOptions and to the value param of the ValueSetter modules - both with only one "$" around the tokens and two "$$"
0 Karma

sideview
SplunkTrust
SplunkTrust

The work has not yet been done to make staticOptions support $foo$-substitution. It probably wont be able to happen for at least a month or two but I can bump it up a bit.

In the meantime the workarounds are to use ValueSetter's with conditional logic. In your case this is only a partial workaround. You want to parametrize both the default value used downstream, and also the default label displayed in the selected option. But this workaround can only achieve the former.

Note: I deleted some things from the <view> tag which shouldn't have been there, and I rolled up your two ValueSetters at the top into one using the arg.* syntax.

And.... this is not a great workaround. It uses some very advanced and rarely-used functionality in ValueSetter, and absolutely staticOptions should support $foo$-substitution. That improvement will get implemented and sorry it has taken so long.

<view autoCancelInterval="90" isVisible="true" onunloadCancelJobs="true" template="dashboard.html">
  <label>Home</label>
  <module name="AccountBar" layoutPanel="appHeader"/>
  <module name="AppBar" layoutPanel="navigationHeader"/>
  <module name="SideviewUtils" layoutPanel="appHeader" />
  <module name="URLLoader" layoutPanel="viewHeader" autoRun="True">

    <module name="ValueSetter">
      <param name="arg.defaultLabel">MyDefaultSite</param>
      <param name="arg.defaultValue">MDS</param>

      <module name="Search">
        <param name="search">...  | table Description, Abbr</param>

        <module name="Pulldown">
          <param name="name">selectedWebsite</param>
          <param name="label">Web Site: </param>
          <param name="staticOptions">
            <!-- Set default website to display when page loads -->
            <list>
              <param name="label">MyDefaultSite</param>
              <param name="value">DEFAULT_VALUE</param>
            </list>
          </param>
          <param name="labelField">Description</param>
          <param name="valueField">Abbr</param>

           <module name="ValueSetter">
             <param name="name">selectedWebsite</param>
             <param name="if.$selectedWebsite$=DEFAULT_VALUE">$defaultValue$</param>
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...