All Apps and Add-ons

$foo$ tokens with default values

martin_mueller
SplunkTrust
SplunkTrust

Is there a way to specify default values of tokens passed through a URLLoader in a SideView Utils enabled view, something like this

$mytoken{default="my default value"}$

?

0 Karma
1 Solution

sideview
SplunkTrust
SplunkTrust

I'm going to give a bit of a circuitous answer, because this is kind of a leading quesiton asking to do something quite complex, and there are usually much simpler ways to get the same basic thing done. I don't want readers who just need one of the simpler answers to start doing things in this complex way.

Some modules have their own way to set defaults. For instance in the Pulldown module when you're configuring static options they can be marked selected. Also the Checkbox and TextField modules have their own default params that may or may not accept $foo$ substitution.

(That is simple exit point one. Use those when you can)

Past all that though, as you quickly learn when using Sideview Utils, if a module has a 'name' param and it sees that same 'name' key coming from upstream, it will try and set its own value to match that upstream value. This is exactly how a module like TextField will prepopulate itself from the URL that URLLoader provides from upstream (and why it's so important that the names in the URL arguments match the appropriate name params exactly for prepopulation to work).

(simple exit point two - you can easily prepopulate "default" things from the URL just by setting the one relevant key in the URL. Sideview docs go into greater detail.)

This also makes for another universal way to set things to values, namely the "ValueSetter" module. ValueSetter is a strange little guy that is useful surprisingly often to do silly little tasks, and it has some odd but useful params that each come in handy once in a blue moon. Here we can use it to not only set the default value for some other key, but also to pick up that default from the URL.

Let's say that we want to have the ability to set a dynamic Pulldown module with ?user=mildred or ?user=bob in the URL. And that we also for whatever reason want to be able to pass a default in the URL itself, so that I guess different links can each specify different defaults

(simple exit point three - when using ValueSetter it's more common to simply hardcode the simple default you're using, rather than picking up the default also from the URL)

So you need defaultUser=admin up there as well. In the end you'll have some links that look like ?user=mildred&defaultUser=admin, where the defaultUser will be ignored, and some links that look like ?user=&defaultUser=admin` where you want the page to pick up the defaultUser key

(simple exit point four - it is MUCH easier to do this with a ValueSetter in the view that you're coming from, because you can simply use a ValueSetter with allowClobber upstream from the Redirector.... That is a far more common solution than this weird thing of passing both the value and it's default in the URL)

OK, so finally, unless you've realized that one of the four "exit points" above actually fits your case better, here's the answer to your question. You make use of the allowClobber param on ValueSetter so that it will set the user key to the defaultUser value only if user is null. As an additional nuance we use the requiredKeys param to make sure that it never clobbers the user key if the defaultUser value is null.

<module name="URLLoader">

  <module name="ValueSetter">
    <param name="name">user</param>
    <param name="allowClobber">False</param>
    <param name="requiredKeys">defaultUser</param>
    <param name="value">$defaultUser$</param>

    <module name="Search">
      <param name="search"> ( your search here, that we use to populate the pulldown) | stats count by user</param>

      <module name="Pulldown">
        <param name="name">user</param>
        <param name="label">User</param>
        <param name="template">$name$="$value$"</param>
        <param name="valueField">$name$</param>

        ... and $user$ goes on to a successful career in various reports and charts and tables...

      </module>
    </module>
  </module>
</module>

View solution in original post

sideview
SplunkTrust
SplunkTrust

I'm going to give a bit of a circuitous answer, because this is kind of a leading quesiton asking to do something quite complex, and there are usually much simpler ways to get the same basic thing done. I don't want readers who just need one of the simpler answers to start doing things in this complex way.

Some modules have their own way to set defaults. For instance in the Pulldown module when you're configuring static options they can be marked selected. Also the Checkbox and TextField modules have their own default params that may or may not accept $foo$ substitution.

(That is simple exit point one. Use those when you can)

Past all that though, as you quickly learn when using Sideview Utils, if a module has a 'name' param and it sees that same 'name' key coming from upstream, it will try and set its own value to match that upstream value. This is exactly how a module like TextField will prepopulate itself from the URL that URLLoader provides from upstream (and why it's so important that the names in the URL arguments match the appropriate name params exactly for prepopulation to work).

(simple exit point two - you can easily prepopulate "default" things from the URL just by setting the one relevant key in the URL. Sideview docs go into greater detail.)

This also makes for another universal way to set things to values, namely the "ValueSetter" module. ValueSetter is a strange little guy that is useful surprisingly often to do silly little tasks, and it has some odd but useful params that each come in handy once in a blue moon. Here we can use it to not only set the default value for some other key, but also to pick up that default from the URL.

Let's say that we want to have the ability to set a dynamic Pulldown module with ?user=mildred or ?user=bob in the URL. And that we also for whatever reason want to be able to pass a default in the URL itself, so that I guess different links can each specify different defaults

(simple exit point three - when using ValueSetter it's more common to simply hardcode the simple default you're using, rather than picking up the default also from the URL)

So you need defaultUser=admin up there as well. In the end you'll have some links that look like ?user=mildred&defaultUser=admin, where the defaultUser will be ignored, and some links that look like ?user=&defaultUser=admin` where you want the page to pick up the defaultUser key

(simple exit point four - it is MUCH easier to do this with a ValueSetter in the view that you're coming from, because you can simply use a ValueSetter with allowClobber upstream from the Redirector.... That is a far more common solution than this weird thing of passing both the value and it's default in the URL)

OK, so finally, unless you've realized that one of the four "exit points" above actually fits your case better, here's the answer to your question. You make use of the allowClobber param on ValueSetter so that it will set the user key to the defaultUser value only if user is null. As an additional nuance we use the requiredKeys param to make sure that it never clobbers the user key if the defaultUser value is null.

<module name="URLLoader">

  <module name="ValueSetter">
    <param name="name">user</param>
    <param name="allowClobber">False</param>
    <param name="requiredKeys">defaultUser</param>
    <param name="value">$defaultUser$</param>

    <module name="Search">
      <param name="search"> ( your search here, that we use to populate the pulldown) | stats count by user</param>

      <module name="Pulldown">
        <param name="name">user</param>
        <param name="label">User</param>
        <param name="template">$name$="$value$"</param>
        <param name="valueField">$name$</param>

        ... and $user$ goes on to a successful career in various reports and charts and tables...

      </module>
    </module>
  </module>
</module>

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

Indeed, thanks!

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

I think I'll need exit point three or five, I'll test & verify that when I'm back on site Thursday after tomorrow's holiday.

This may be one of the largest answer-to-question word count ratio 🙂 thanks!

0 Karma
Did you miss .conf21 Virtual?

Good news! The event's keynotes and many of its breakout sessions are now available online, and still totally FREE!