Dashboards & Visualizations

Add to a dynamic dropdown

dbcase
Motivator

Hi,

I have this XML code

 <input type="dropdown" token="Product_token" searchWhenChanged="true">
      <label>Select a Product</label>
      <search>
      <query>index=wholesale_app  product|dedup product</query>
      <earliest>-1d</earliest>
        <latest>now</latest>
      </search>

      <fieldForLabel>product</fieldForLabel>
      <fieldForValue>product</fieldForValue>


    </input>

And it works just fine. I populates a dropdown with 2 values (lets call them Product 1 and Product 2) and I have working queries that adjust when the user selects one of the two products. So far so good. Now what I'd like to do is manually insert a "all" product so the users can select it and will see all the values regardless of product. Is there a way to manually insert a value to a dynamic dropdown?

1 Solution

Javip
Path Finder

Hi!

Try this:

  <input type="dropdown" token="Product_token" searchWhenChanged="true">
       <label>Select a Product</label>
       <search>
       <query>index=wholesale_app  product|dedup product</query>
       <earliest>-1d</earliest>
         <latest>now</latest>
       </search>
       <fieldForLabel>product</fieldForLabel>
       <fieldForValue>product</fieldForValue>

       <choice value="*">- All -</choice>
      <default>*</default>
      <initialValue>*</initialValue>
     </input>

Tell me if it's ok for you 🙂
Regards!

View solution in original post

elliotproebstel
Champion

There's probably a good way to do this with token manipulation, too, but I have an idea for how to append a small bit of SPL to the end of your query and slightly change the XML to reach your goal. If you add a field called "product_name" to each event and fill it with the current value of "product" and then append a dummy event with product_name="All" and product="*", and then modify your XML slightly to use the fieldForLabel of product_name, then you should be set. So all together, it looks like this:

 <input type="dropdown" token="Product_token" searchWhenChanged="true">
       <label>Select a Product</label>
       <search>
       <query>index=wholesale_app  product|dedup product | eval product_name=product | append [| stats count | eval product="*", product_name="All" | fields - count]</query>
       <earliest>-1d</earliest>
         <latest>now</latest>
       </search>
       <fieldForLabel>product_name</fieldForLabel>
       <fieldForValue>product</fieldForValue>
</input>
0 Karma

Javip
Path Finder

Hi!

Try this:

  <input type="dropdown" token="Product_token" searchWhenChanged="true">
       <label>Select a Product</label>
       <search>
       <query>index=wholesale_app  product|dedup product</query>
       <earliest>-1d</earliest>
         <latest>now</latest>
       </search>
       <fieldForLabel>product</fieldForLabel>
       <fieldForValue>product</fieldForValue>

       <choice value="*">- All -</choice>
      <default>*</default>
      <initialValue>*</initialValue>
     </input>

Tell me if it's ok for you 🙂
Regards!

dbcase
Motivator

Hi Javip,

Wow, that was simple! Many many thanks!!!!

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...