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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...