Dashboards & Visualizations

how to dynamically display the username in an input ?

mah
Contributor

Hi, 

I tried to set an input which displays the name of the user who open the dashboard. 

I tried a dropdown input  where the default is my username and it works well : 

mah_0-1615823673103.png

But my username appears when other user open the dashboard with their own username (they have both mine and theirs), instead only theirs. 

So I checked the code, and what I found is when I select mine as default, it retained mine in the code :

<input type="dropdown" token="user_tok" searchWhenChanged="true">
<label>your username is :</label>
<fieldForLabel>username</fieldForLabel>
<fieldForValue>username</fieldForValue>
<search>
<query>| rest /services/authentication/current-context splunk_server=local
| fields roles username
| mvexpand roles
| fields username</query>
</search>
<change>
<condition match="isnotnull($value$) AND $value$!=&quot;&quot;">
<set token="tokTextFilter">$value$</set>
</condition>
</change>
<default>gxxxx</default>

 

mah_1-1615824133816.png

I tried to set the token input in the default : 

<default>$user_tok$</default>

But nothing changed.

How can I set by default and displays only the username who goes to the dashboard ? 

Thanks for your help !

Labels (1)
0 Karma

Vardhan
Contributor

Hi,

Can you try the below one.

<input type="dropdown" token="user">
<label>field1</label>
<prefix>user_token</prefix>
<fieldForLabel>username</fieldForLabel>
<fieldForValue>username</fieldForValue>
<search>
<query>| rest /services/authentication/current-context splunk_server=local
| fields roles username
| mvexpand roles
| fields username</query>
<earliest>-24h@h</earliest>
<latest>now</latest>
</search>
</input>

0 Karma

mah
Contributor

I tried your code, but it gave me this :

mah_0-1615882829598.png

What I want is to have automatically the username selected by default, and not to click on "Select". 

That's why I tried to put the token into the <default> value, but it does not work at all. 

I use this user token in multiple queries on my dashboard, and since there is only one value for a user then I would like this value to be the default.

0 Karma
Register for .conf21 Now! Go Vegas or Go Virtual!

How will you .conf21? You decide! Go in-person in Las Vegas, 10/18-10/21, or go online with .conf21 Virtual, 10/19-10/20.