Dashboards & Visualizations
Highlighted

Why is my dynamic dropdown not updating using selectFirstChoice and token unset?

Builder

I have a dashboard with dynamically populated dropdown inputs. Selecting input A sets tokenA that the input B relies on for its populating search. I used + to unset tokenB when the selection in input A changes and this works just fine unless I reload the browser after I've made my selection; if I do this token_B resets but the first option is not selected.

Here is input A (A list of available Datamodels):

<input type="dropdown" token="data_model" searchWhenChanged="false">
      <label>Data Model</label>
      <search>
        <query>| rest /services/datamodel/model | search eai:acl.app!=search | table displayName title eai:acl.app | sort displayName</query>
      </search>
      <fieldForLabel>displayName</fieldForLabel>
      <fieldForValue>title</fieldForValue>
      <change>
        <unset token="form.root_object_name"></unset>
      </change>
    </input>

Here is input B (Datamodel Root Object Name):

<input type="dropdown" token="root_object_name" searchWhenChanged="true">
      <label>Root Object Name</label>
      <selectFirstChoice>true</selectFirstChoice>
      <fieldForLabel>object_name</fieldForLabel>
      <fieldForValue>object</fieldForValue>
      <search>
        <query>| datamodel $data_model$ | spath | rename "objects{}.displayName" as object_name "objects{}.objectName" as object | table object | mvexpand object | head 1</query>
        <earliest>-24h@h</earliest>
        <latest>now</latest>
      </search>

I've read questions that lead me to a solution but it doesn't seem to work when I reload my dashboard. I'm using Splunk 6.5.2.

Highlighted

Re: Why is my dynamic dropdown not updating using selectFirstChoice and token unset?

Legend

Instead of using unset code on change event and then setting of token in second input, you can enable searchWhenChanged in data_model input

<input type="dropdown" token="data_model" searchWhenChanged="true">

And remove the unset token code in change event and the value of second dropdown will not reset on refresh.

   <change>
     <unset token="form.root_object_name"></unset>
   </change>
0 Karma
Highlighted

Re: Why is my dynamic dropdown not updating using selectFirstChoice and token unset?

Builder

Does that work for you? The behavior is similar when I do this. If I navigate to this dashboard for the first time or clear the URL so none of the token values are present then the dashboard appears to work as it should. Now when I reload my browser the last value for tokenB seems to be stuck. If I change the value of tokenA the value of tokenB is not updated and the dropdown is still populated with the previous selection. I can change it but again, selecting a new value for tokenA doesn't update token_B.

I went down this road before attempting to use unset but I did change my XML just to confirm. If this is working for you then it might be a browser issue. I'll try something other than Chrome.

I'd like this to work without any user input for token_B so I can hide that input selection ... perhaps there is a more elegant way to do that an I should be asking that.

0 Karma
Highlighted

Re: Why is my dynamic dropdown not updating using selectFirstChoice and token unset?

Legend

@dflodstrom... following works for me (I have taken out one condition in REST query to fetch all Data Models for testing).

  <fieldset submitButton="false">
    <input type="dropdown" token="data_model" searchWhenChanged="true">
      <label>Data Model</label>
      <search>
        <query>| rest /services/datamodel/model | table displayName title eai:acl.app | sort displayName</query>
      </search>
      <fieldForLabel>displayName</fieldForLabel>
      <fieldForValue>title</fieldForValue>
    </input>
    <input type="dropdown" token="root_object_name" searchWhenChanged="true">
      <label>Root Object Name</label>
      <selectFirstChoice>true</selectFirstChoice>
      <fieldForLabel>object_name</fieldForLabel>
      <fieldForValue>object</fieldForValue>
      <search>
        <query>| datamodel $data_model$ | spath | rename "objects{}.displayName" as object_name "objects{}.objectName" as object | table object | mvexpand object | head 1</query>
        <earliest>-24h@h</earliest>
        <latest>now</latest>
      </search>
    </input>
  </fieldset>

The above will not loose previous value for dropdown B on refresh and everything will reset when you clear the querystrings(form variables through browser URL). I don't think output would vary for different browsers.
PS: You can use $datamodels$ as depends token for dropdown B so that it is hidden when any datamodels is not selected.

0 Karma
Highlighted

Re: Why is my dynamic dropdown not updating using selectFirstChoice and token unset?

Builder

I've replaced my inputs with your code and the behavior remains the same. Everything appears to be working just fine until I reload my browser window. When I do that the previous value for token_B remains when the value for Data Model is changed. The dropdown is updated, it only displays one value aside from the currently populated value.

I want to hide this input panel because it should not require interaction, I'll use a depends token but one that isn't ever set so it never shows.

0 Karma
Highlighted

Re: Why is my dynamic dropdown not updating using selectFirstChoice and token unset?

Builder

If you tested the code in my question you'll see that it functions also, but not when I refresh my browser.

https://answers.splunk.com/answers/218751/selectfirstchoice-not-working-in-dynamic-dropdowns.html

0 Karma
Highlighted

Re: Why is my dynamic dropdown not updating using selectFirstChoice and token unset?

Builder

I'm having the same issue in Firefox as I am in Chrome. If I send someone a link to this dashboard with the tokens already populated token_B won't get updated automatically.

0 Karma
Highlighted

Re: Why is my dynamic dropdown not updating using selectFirstChoice and token unset?

Legend

@dflodstorm I am sorry but I did not come up with right solution for you. I have provided an option which should meet your requirement however, it is on a different approach since selectFirstChoice has a limitation for refresh which you have encountered.

One more possible option with map command works in Splunk search but not in Dashboard. You could have got the title from first search and then used the map command to run the datamodel subsearch for returned results. Unfortunately, while this works in Splunk Search I could not get it to work in dashboard 😞

| rest /services/datamodel/model | table displayName title eai:acl.app | sort displayName
| map search=" | datamodel $title$ | spath | rename \"objects{}.displayName\" as object_name \"objects{}.objectName\" as object | table object_name object | mvexpand object_name | mvexpand object | head 1"
0 Karma
Highlighted

Re: Why is my dynamic dropdown not updating using selectFirstChoice and token unset?

Explorer

This worked for me... Thanks niketnilay

0 Karma
Highlighted

Re: Why is my dynamic dropdown not updating using selectFirstChoice and token unset?

Explorer

Please take a look on this link:
Approach A: Two Inputs, One Token
https://www.splunk.com/blog/2017/04/04/build-a-dashboard-with-dynamic-and-editable-inputs.html?linkI...

0 Karma
Speak Up for Splunk Careers!

We want to better understand the impact Splunk experience and expertise has has on individuals' careers, and help highlight the growing demand for Splunk skills.