Dashboards & Visualizations

How to pass a search based on the token value from a text field?

splunkrocks2014
Communicator

I have a text field with default/initial value set to "". I wanted to use different search queries based on the values from the textfield which is mainly "" or not "*". Any suggestion? Thanks.

<form>
  <fieldset submitButton="false">
    <input type="text" token="tok_text" searchWhenChanged="true">
      <label>text</label>
      <default>*</default>
      <initialValue>*</initialValue>
      <change>
         <condition value="*">
           <set token="searchOne"></set>
           <unset token="searchTwo"></unset>
         </condition>
         <condition value!="*">  <!-- it doesn't support not equal to -->
           <unset token="searchOne"></unset>
           <set token="searchTwo"></set>
         </condition>
       </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <single depends="$searchOne$">
        <title>Search No Star</title>
        <search>
          <query>| makeresults | eval nonstar="$tok_text$" | stats values(nostar)</query>
          <earliest>-15m@m</earliest>
          <latest>now</latest>
        </search>
      </single>
      <single depends="$searchTwo$">
        <title>Search Star</title>
        <search>
          <query>| makeresults | eval star="$tok_text$" | stats values(star)</query>
          <earliest>-1d@d</earliest>
          <latest>now</latest>
        </search>
      </single>
    </panel>
  </row>
</form>
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

Hi @splunkrocks2014,

value is an attribute of condition tag. SO you can not use != for an attribute, but you can use match attribute for your requirement.

Can you please try Condition from below XML ???

<form>
   <fieldset submitButton="false">
     <input type="text" token="tok_text" searchWhenChanged="true">
       <label>text</label>
       <default>*</default>
       <initialValue>*</initialValue>
       <change>
          <condition match="'value'!=&quot;*&quot;">
            <unset token="searchOne"></unset>
            <set token="searchTwo">searchTwo</set>
          </condition>
          <condition>
            <set token="searchOne">searchOne</set>
            <unset token="searchTwo"></unset>
          </condition>
        </change>
     </input>
   </fieldset>
   <row>
     <panel>

       <single depends="$searchOne$">
         <title>Search No Star</title>
         <search>
           <query>| makeresults | eval nonstar="$tok_text$" | stats values(nostar)</query>
           <earliest>-15m@m</earliest>
           <latest>now</latest>
         </search>
       </single>
       <single depends="$searchTwo$">
         <title>Search Star</title>
         <search>
           <query>| makeresults | eval star="$tok_text$" | stats values(star)</query>
           <earliest>-1d@d</earliest>
           <latest>now</latest>
         </search>
       </single>
     </panel>
   </row>
 </form>

Thanks

View solution in original post

kamlesh_vaghela
SplunkTrust
SplunkTrust

Hi @splunkrocks2014,

value is an attribute of condition tag. SO you can not use != for an attribute, but you can use match attribute for your requirement.

Can you please try Condition from below XML ???

<form>
   <fieldset submitButton="false">
     <input type="text" token="tok_text" searchWhenChanged="true">
       <label>text</label>
       <default>*</default>
       <initialValue>*</initialValue>
       <change>
          <condition match="'value'!=&quot;*&quot;">
            <unset token="searchOne"></unset>
            <set token="searchTwo">searchTwo</set>
          </condition>
          <condition>
            <set token="searchOne">searchOne</set>
            <unset token="searchTwo"></unset>
          </condition>
        </change>
     </input>
   </fieldset>
   <row>
     <panel>

       <single depends="$searchOne$">
         <title>Search No Star</title>
         <search>
           <query>| makeresults | eval nonstar="$tok_text$" | stats values(nostar)</query>
           <earliest>-15m@m</earliest>
           <latest>now</latest>
         </search>
       </single>
       <single depends="$searchTwo$">
         <title>Search Star</title>
         <search>
           <query>| makeresults | eval star="$tok_text$" | stats values(star)</query>
           <earliest>-1d@d</earliest>
           <latest>now</latest>
         </search>
       </single>
     </panel>
   </row>
 </form>

Thanks

splunkrocks2014
Communicator

Thanks, this is what i am looking for.

0 Karma

DalJeanis
Legend

You can use <condition> with no test, as per the example under "Search tokens for dynamic display example" on this page:

http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/Viz/tokens

0 Karma

splunkrocks2014
Communicator

It doesn't seem working. Thanks anyway

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...