<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How can I set a token to the current logged-in username in SimpleXML dashboards without using Javascript? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-set-a-token-to-the-current-logged-in-username-in/m-p/253270#M15806</link>
    <description>&lt;P&gt;Here is some example code. You need to be running Splunk 6.3 or greater, and you use the "finalized" handler to set a token to the first search results from a REST search that returns the current username (in the field 'title').  The example also shows a "depends" on the table that never gets set ($neverdisplay$), so the table that runs the search remains hidden, although the search runs and the token gets populated.&lt;/P&gt;

&lt;P&gt;With the example below you will have a new token called "loggedinuser" that you can then use throughout the rest of the dashboard.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard&amp;gt;
      &amp;lt;label&amp;gt;Token Tester&amp;lt;/label&amp;gt;
      &amp;lt;row&amp;gt;
        &amp;lt;panel&amp;gt;
          &amp;lt;table depends="$neverdisplay$"&amp;gt;
            &amp;lt;title&amp;gt;get a token&amp;lt;/title&amp;gt;
            &amp;lt;search&amp;gt;
              &amp;lt;query&amp;gt;|rest /services/authentication/users splunk_server=local | search [| rest /services/authentication/current-context splunk_server=local | rename username as title | fields title]&amp;lt;/query&amp;gt;
              &amp;lt;earliest&amp;gt;-60m&amp;lt;/earliest&amp;gt;
              &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
              &amp;lt;finalized&amp;gt;
                &amp;lt;set token="loggedinuser"&amp;gt;$result.title$&amp;lt;/set&amp;gt;
              &amp;lt;/finalized&amp;gt;
            &amp;lt;/search&amp;gt;
          &amp;lt;/table&amp;gt;
        &amp;lt;/panel&amp;gt;
        &amp;lt;panel&amp;gt;
          &amp;lt;title&amp;gt;Token Display&amp;lt;/title&amp;gt;
          &amp;lt;html&amp;gt;
            &amp;lt;h3&amp;gt;Logged In User Token is...&amp;lt;/h3&amp;gt;
              &amp;lt;div class="custom-result-value"&amp;gt;$loggedinuser$&amp;lt;/div&amp;gt;
          &amp;lt;/html&amp;gt;
        &amp;lt;/panel&amp;gt;
      &amp;lt;/row&amp;gt;
    &amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 04 Oct 2015 04:14:58 GMT</pubDate>
    <dc:creator>jbrodsky_splunk</dc:creator>
    <dc:date>2015-10-04T04:14:58Z</dc:date>
    <item>
      <title>How can I set a token to the current logged-in username in SimpleXML dashboards without using Javascript?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-set-a-token-to-the-current-logged-in-username-in/m-p/253269#M15805</link>
      <description>&lt;P&gt;How can I retrieve the current username of a SplunkWeb user, and use that value in a token so that I can automatically customize subsequent searches on the dashboard to that username? I don't want to use any Javascript and I don't want to have to convert my dashboard to HTML to do this.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Oct 2015 04:11:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-set-a-token-to-the-current-logged-in-username-in/m-p/253269#M15805</guid>
      <dc:creator>jbrodsky_splunk</dc:creator>
      <dc:date>2015-10-04T04:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: How can I set a token to the current logged-in username in SimpleXML dashboards without using Javascript?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-set-a-token-to-the-current-logged-in-username-in/m-p/253270#M15806</link>
      <description>&lt;P&gt;Here is some example code. You need to be running Splunk 6.3 or greater, and you use the "finalized" handler to set a token to the first search results from a REST search that returns the current username (in the field 'title').  The example also shows a "depends" on the table that never gets set ($neverdisplay$), so the table that runs the search remains hidden, although the search runs and the token gets populated.&lt;/P&gt;

&lt;P&gt;With the example below you will have a new token called "loggedinuser" that you can then use throughout the rest of the dashboard.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard&amp;gt;
      &amp;lt;label&amp;gt;Token Tester&amp;lt;/label&amp;gt;
      &amp;lt;row&amp;gt;
        &amp;lt;panel&amp;gt;
          &amp;lt;table depends="$neverdisplay$"&amp;gt;
            &amp;lt;title&amp;gt;get a token&amp;lt;/title&amp;gt;
            &amp;lt;search&amp;gt;
              &amp;lt;query&amp;gt;|rest /services/authentication/users splunk_server=local | search [| rest /services/authentication/current-context splunk_server=local | rename username as title | fields title]&amp;lt;/query&amp;gt;
              &amp;lt;earliest&amp;gt;-60m&amp;lt;/earliest&amp;gt;
              &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
              &amp;lt;finalized&amp;gt;
                &amp;lt;set token="loggedinuser"&amp;gt;$result.title$&amp;lt;/set&amp;gt;
              &amp;lt;/finalized&amp;gt;
            &amp;lt;/search&amp;gt;
          &amp;lt;/table&amp;gt;
        &amp;lt;/panel&amp;gt;
        &amp;lt;panel&amp;gt;
          &amp;lt;title&amp;gt;Token Display&amp;lt;/title&amp;gt;
          &amp;lt;html&amp;gt;
            &amp;lt;h3&amp;gt;Logged In User Token is...&amp;lt;/h3&amp;gt;
              &amp;lt;div class="custom-result-value"&amp;gt;$loggedinuser$&amp;lt;/div&amp;gt;
          &amp;lt;/html&amp;gt;
        &amp;lt;/panel&amp;gt;
      &amp;lt;/row&amp;gt;
    &amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Oct 2015 04:14:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-set-a-token-to-the-current-logged-in-username-in/m-p/253270#M15806</guid>
      <dc:creator>jbrodsky_splunk</dc:creator>
      <dc:date>2015-10-04T04:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: How can I set a token to the current logged-in username in SimpleXML dashboards without using Javascript?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-set-a-token-to-the-current-logged-in-username-in/m-p/253271#M15807</link>
      <description>&lt;P&gt;Now there is a new option, $env:user$   Current user's user name&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.0.0/Viz/tokens" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/7.0.0/Viz/tokens&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;There are some other useful tokens pre-defined by who is running the dashboard, most are available I think from 6.5+ &lt;/P&gt;

&lt;P&gt;Name    Description&lt;BR /&gt;
$env:user$  Current user's user name&lt;BR /&gt;
$env:user_realname$ Current user full name.&lt;BR /&gt;
$env:user_email$    Current user email address.&lt;BR /&gt;
$env:app$   Current app context&lt;BR /&gt;
$env:locale$    Current locale&lt;BR /&gt;
$env:page$  Currently open page&lt;BR /&gt;
$env:product$   Current instance product type&lt;BR /&gt;
$env:instance_type$ Indicates whether the current instance is Splunk Cloud or an on-premises deployment&lt;BR /&gt;
$env:is_cloud$  Indicates if the current instance is Splunk Cloud. This token is only set when "true".&lt;BR /&gt;
$env:is_enterprise$ Indicates if the current instance is a Splunk Enterprise deployment. This token is only set when "true".&lt;BR /&gt;
$env:is_hunk$   Indicates if the current instance is a Hunk deployment. This token is only set when "true".&lt;BR /&gt;
$env:is_lite$   Indicates if the current instance is a Splunk Light deployment. This token is only set when "true".&lt;BR /&gt;
$env:is_lite_free$  Indicates if the current instance is using a Splunk Light free license. This token is only set when "true".&lt;BR /&gt;
$env:is_free$   Indicates if the current instance is using a Splunk Enterprise free license. This token is only set when "true".&lt;BR /&gt;
$env:version$   Current instance product version&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:10:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-set-a-token-to-the-current-logged-in-username-in/m-p/253271#M15807</guid>
      <dc:creator>twollenslegel_s</dc:creator>
      <dc:date>2020-09-29T16:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: How can I set a token to the current logged-in username in SimpleXML dashboards without using Javascript?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-set-a-token-to-the-current-logged-in-username-in/m-p/253272#M15808</link>
      <description>&lt;P&gt;$env:user$ only works some times. Sometimes it will pass the user ID of another logged on user. &lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 21:09:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-set-a-token-to-the-current-logged-in-username-in/m-p/253272#M15808</guid>
      <dc:creator>jbillings</dc:creator>
      <dc:date>2019-03-11T21:09:22Z</dc:date>
    </item>
  </channel>
</rss>

