Dashboards & Visualizations

How to create a dependent dropdown based on the values of the first dropdown

adamantium7706
Explorer

I am trying to create a dependent dropdown based on the first dropdown. 

There is a list of users who have multiple usernames and each username has a specific id and a panel needs to be populated based on the id.

Users: ABC, DEF, GHI, JKL

Usernames
ABC: aaa, bbb, ccc
DEF: ddd, eee
GHI: ggg
JKL: jjj, kkk

ID
aaa: 1111
bbb: 2222
ccc: 3333
ddd: 4444
eee: 5555
ggg: 6666
jjj: 7777
kkk: 8888

Once the user is selected in the first dropdown, the second dropdown should only show the usernames for that particular user.

Any help will be really appreciated.

Labels (1)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @adamantium7706,

in the second dropdown search, you have to add the token from the first dropdown, something like this:

if the first token is called $users$, in thesecond search you have to use

<second_dropdown_main_search> username=$user$
| dedup username
| sort username
| table username

I could be more precise if you can share the two searches.

Ciao.

Giuseppe

adamantium7706
Explorer

Thanks for the reply. Here is the code:

 

<form>
  <label>DEMO</label>
  <fieldset submitButton="false">
    <input type="dropdown" token="User_tok" searchWhenChanged="true">
      <label>Users</label>
      <choice value="ABC">ABC</choice>
      <choice value="DEF">DEF</choice>
      <choice value="GHI">GHI</choice>
      <choice value="JKL">JKL</choice>
      <change>
        <unset token="Uname_tok"></unset>
        <unset token="form.Uname_tok"></unset>
      </change>
    </input>
    <input type="dropdown" token="Uname_tok" searchWhenChanged="true">
      <label>Label </label>
      <fieldForLabel>$User_tok$</fieldForLabel>
      <fieldForValue>$User_tok$</fieldForValue>
      <search>
        <query>| makeresults
| fields - _time
| eval ABC="aaa,bbb,ccc", DEF="ddd,eee", GHI="ggg", JKL="jjj,kkk"
| fields $User_tok$
| makemv $User_tok$ delim=","
| mvexpand $User_tok$</query>
      </search>
    </input>
  </fieldset>
  <row>
    <panel>
      <table>
        <title>Demo</title>
        <search>
          <query>index=* sourcetype=source name=$Uname_tok$ 
| stats count by uname, id….
</query>
          <earliest>-1y@y</earliest>
          <latest>@y</latest>
        </search>
        <option name="drilldown">none</option>
        <option name="refresh.display">progressbar</option>
      </table>
    </panel>
  </row>
</form>

 

As stated, each username has an assigned ID. So rather than searching with the username (name=$ Uname_tok$), I want to search using the ID assigned to the user. So, while searching for "aaa" I want to search using "1111" in the query.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @adamantium7706,

please adapt this example to your requirements:

<form>
  <label>DEMO</label>
  <fieldset submitButton="false">
    <input type="dropdown" token="User_tok" searchWhenChanged="true">
      <label>Users</label>
      <choice value="ABC">ABC</choice>
      <choice value="DEF">DEF</choice>
      <choice value="GHI">GHI</choice>
      <choice value="JKL">JKL</choice>
      <change>
        <unset token="Uname_tok"></unset>
        <unset token="form.Uname_tok"></unset>
      </change>
    </input>
    <input type="dropdown" token="Uname_tok" searchWhenChanged="true">
      <label>Label </label>
      <fieldForLabel>uname</fieldForLabel>
      <fieldForValue>uname</fieldForValue>
      <search>
        <query>
           | makeresults
           | fields - _time
           | eval ABC="aaa,bbb,ccc", DEF="ddd,eee", GHI="ggg", JKL="jjj,kkk"
           | transpose
           | rename column AS user "row 1" AS name
           | makemv delim="," name
           | mvexpand name
           | search user="$User_tok$"
           | table name
        </query>
      </search>
    </input>
  </fieldset>
  <row>
    <panel>
      <table>
        <title>Demo</title>
        <search>
          <query>
             index=* sourcetype=source name="$Uname_tok$"
             | stats count by uname, id….
          </query>
          <earliest>-1y@y</earliest>
          <latest>@y</latest>
        </search>
        <option name="drilldown">none</option>
        <option name="refresh.display">progressbar</option>
      </table>
    </panel>
  </row>
</form>

In few words, you need, in the second search, To have a two columns table: the first with the value to search for filtering and the second to use as token in the panel's search.

Ciao.

Giuseppe

0 Karma
Get Updates on the Splunk Community!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...