Dashboards & Visualizations

Unsetting tokens defined by other tokens

cmzhu
Explorer

I have a dashboard where the token CgClassUserId is being populated from a dropdown, and then other tokens (like CgClass) are being evaluated subsequently. I want to set a token s_class to be true if CgClass == 'S' and unset it if not.

I am currently attempting this by having a change and condition match block of code after evaluating tokens like CgClass. However, with the addition of this code, when I change the CgClassUserId token, the subsequent eval tokens like CgClass are no longer changing as well.

   <input type="dropdown" token="CgClassUserId" searchWhenChanged="true">
          <label>Application</label>
          <fieldForLabel>Application</fieldForLabel>
          <fieldForValue>CgClassUserId</fieldForValue>
          <search>
            <query>| inputlookup ActivCgApplicationLookup.csv
    | eval CgClassUserId=CgClass.UserId
    | sort +Application</query>
            <earliest>0</earliest>
            <latest></latest>
          </search>
          <change>
            <!-- Use predefined input token $label$ to set Application token to selected label -->
            <set token="Application">$label$</set>
            <!-- Extract CgClass and UserId values from combined CgClassUserId for selected Application -->
            <eval token="CgClass">substr($CgClassUserId$,1,1)</eval>
            <eval token="CgClassClause">"host=\"*-".lower($CgClass$)."-*\""</eval>
            <eval token="UserId">substr($CgClassUserId$,2)</eval>
          </change>


          <change>
            <condition match="$CgClass$ != &quot;S&quot;">
              <unset token="s_class"></unset>
              <unset token="form.s_class"></unset>
            </condition>
            <condition match="$CgClass$ == &quot;S&quot;">
              <set token="s_class">true</set>
            </condition>
          </change> 
        </input>
0 Karma
1 Solution

rjthibod
Champion

The issue is you can only have one <change> block, so you have to consolidate everything.

<change>
  <condition match="substr($CgClassUserId$,1,1) != &quot;S&quot;">
    <set token="Application">$label$</set>
    <eval token="CgClass">substr($CgClassUserId$,1,1)</eval>
    <eval token="CgClassClause">"host=\"*-".lower($CgClass$)."-*\""</eval>
    <eval token="UserId">substr($CgClassUserId$,2)</eval>
    <unset token="form.s_class"></unset>
  </condition>
  <condition match="substr($CgClassUserId$,1,1) == &quot;S&quot;">
    <set token="Application">$label$</set>
    <eval token="CgClass">substr($CgClassUserId$,1,1)</eval>
    <eval token="CgClassClause">"host=\"*-".lower($CgClass$)."-*\""</eval>
    <eval token="UserId">substr($CgClassUserId$,2)</eval>
    <set token="form.s_class">true</set>
  </condition>
</change>

View solution in original post

rjthibod
Champion

The issue is you can only have one <change> block, so you have to consolidate everything.

<change>
  <condition match="substr($CgClassUserId$,1,1) != &quot;S&quot;">
    <set token="Application">$label$</set>
    <eval token="CgClass">substr($CgClassUserId$,1,1)</eval>
    <eval token="CgClassClause">"host=\"*-".lower($CgClass$)."-*\""</eval>
    <eval token="UserId">substr($CgClassUserId$,2)</eval>
    <unset token="form.s_class"></unset>
  </condition>
  <condition match="substr($CgClassUserId$,1,1) == &quot;S&quot;">
    <set token="Application">$label$</set>
    <eval token="CgClass">substr($CgClassUserId$,1,1)</eval>
    <eval token="CgClassClause">"host=\"*-".lower($CgClass$)."-*\""</eval>
    <eval token="UserId">substr($CgClassUserId$,2)</eval>
    <set token="form.s_class">true</set>
  </condition>
</change>

cmzhu
Explorer

Thanks so much!

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