<?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: Simple XML Setting Token Value from Javascript not working in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Simple-XML-Setting-Token-Value-from-Javascript-not-working/m-p/353187#M23047</link>
    <description>&lt;P&gt;You can have the visualization panel hidden until the token is set using &lt;CODE&gt;depends=$maxResults$&lt;/CODE&gt;, or else you would need to somehow set the default token value, for example through &lt;CODE&gt;&amp;lt;init&amp;gt;&lt;/CODE&gt; section (similar to how I have created in my run anywhere example above:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;init set token="maxResults"&amp;gt;10&amp;lt;/init&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If one of the options above does not satisfy your needs, you might have to add sample code of the search and place where it is set. So that we can assist further.&lt;/P&gt;</description>
    <pubDate>Wed, 20 Dec 2017 03:19:42 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-12-20T03:19:42Z</dc:date>
    <item>
      <title>Simple XML Setting Token Value from Javascript not working</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Simple-XML-Setting-Token-Value-from-Javascript-not-working/m-p/353183#M23043</link>
      <description>&lt;P&gt;Have created the following javascript file miq_common_tokens.js and have located in ..\myapp\appserver\static\miq_common_tokens.js&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
    "splunkjs/mvc",
    "splunkjs/mvc/simplexml/ready!"
], function(mvc) {

    var tokens = mvc.Components.get("default");
    tokens.set("someGlobalValueToken", "This is a TEST"); 

    }); 
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Have this in my simple xml code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form hideSplunkBar="false" hideFooter="false" script="miq_common_tokens.js,showtokens.js"&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Trying to access the token:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;title&amp;gt;Diagnostic report locations - pass (green), warning (yellow), or failure (red) $reachedMaxLocationsToken$ - $someGlobalValueToken$&amp;lt;/title&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which is displaying:&lt;BR /&gt;
Diagnostic report locations - pass (green), warning (yellow), or failure (red) - Locations truncated at 10 - $someGlobalValueToken$&lt;/P&gt;

&lt;P&gt;And showtokens.js does not show - someGlobalValueToken&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:19:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Simple-XML-Setting-Token-Value-from-Javascript-not-working/m-p/353183#M23043</guid>
      <dc:creator>simpkins1958</dc:creator>
      <dc:date>2020-09-29T17:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Simple XML Setting Token Value from Javascript not working</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Simple-XML-Setting-Token-Value-from-Javascript-not-working/m-p/353184#M23044</link>
      <description>&lt;P&gt;@simpkins1958, in your JavaScript Code Snippet there seems to be an extra closing block &lt;CODE&gt;});&lt;/CODE&gt;. Not sure if it is actually required in your code or typo error while createing code snippet. Also once you have saved the JavaScript, have you tried rebooting/refreshing or bumping Splunk and clearing out internet browser history?&lt;/P&gt;

&lt;P&gt;I tried similar JavaScript code and it worked fine for me.&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/4039iFB6259F6D0961183/image-size/large?v=v2&amp;amp;px=999" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;PS: I have used &lt;CODE&gt;&amp;lt;init&amp;gt;&lt;/CODE&gt; section to initialize couple of tokens to set to default values.&lt;/P&gt;

&lt;P&gt;Following is the run anywhere Simple XML Code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form hideSplunkBar="false" hideFooter="false" script="miq_common_tokens.js"&amp;gt;
  &amp;lt;label&amp;gt;Set token through JavaScript&amp;lt;/label&amp;gt;
  &amp;lt;init&amp;gt;
    &amp;lt;set token="reachedMaxLocationsToken"&amp;gt;10&amp;lt;/set&amp;gt;
    &amp;lt;set token="someGlobalValueToken"&amp;gt;Initialize Token&amp;lt;/set&amp;gt;
  &amp;lt;/init&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Diagnostic report locations - pass (green), warning (yellow), or failure (red) $reachedMaxLocationsToken$ - $someGlobalValueToken$&amp;lt;/title&amp;gt;
      &amp;lt;html&amp;gt;
        &amp;lt;!-- Empty HTML section to avoid XML Parser Warning for Empty Panel--&amp;gt;
      &amp;lt;/html&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is the JavaScript Code &lt;CODE&gt;miq_common_tokens.js&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
     "splunkjs/mvc",
     "splunkjs/mvc/simplexml/ready!"
 ], function(mvc) {
     var tokens = mvc.Components.get("default");
     tokens.set("someGlobalValueToken", "This is a TEST");
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Splunk refresh/restart/_bump may be required for JavaScript changes to reflect. Also internet browser history might need to be cleared up.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 21:12:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Simple-XML-Setting-Token-Value-from-Javascript-not-working/m-p/353184#M23044</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-12-19T21:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: Simple XML Setting Token Value from Javascript not working</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Simple-XML-Setting-Token-Value-from-Javascript-not-working/m-p/353185#M23045</link>
      <description>&lt;P&gt;It was the extra }); - Thanks!!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 21:23:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Simple-XML-Setting-Token-Value-from-Javascript-not-working/m-p/353185#M23045</guid>
      <dc:creator>simpkins1958</dc:creator>
      <dc:date>2017-12-19T21:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: Simple XML Setting Token Value from Javascript not working</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Simple-XML-Setting-Token-Value-from-Javascript-not-working/m-p/353186#M23046</link>
      <description>&lt;P&gt;I am setting a token as the value to use in SPL head command, head $maxResults$. The search is trying to execute before $maxResults$ is available. Anyway to fix this? Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 22:28:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Simple-XML-Setting-Token-Value-from-Javascript-not-working/m-p/353186#M23046</guid>
      <dc:creator>simpkins1958</dc:creator>
      <dc:date>2017-12-19T22:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Simple XML Setting Token Value from Javascript not working</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Simple-XML-Setting-Token-Value-from-Javascript-not-working/m-p/353187#M23047</link>
      <description>&lt;P&gt;You can have the visualization panel hidden until the token is set using &lt;CODE&gt;depends=$maxResults$&lt;/CODE&gt;, or else you would need to somehow set the default token value, for example through &lt;CODE&gt;&amp;lt;init&amp;gt;&lt;/CODE&gt; section (similar to how I have created in my run anywhere example above:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;init set token="maxResults"&amp;gt;10&amp;lt;/init&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If one of the options above does not satisfy your needs, you might have to add sample code of the search and place where it is set. So that we can assist further.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 03:19:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Simple-XML-Setting-Token-Value-from-Javascript-not-working/m-p/353187#M23047</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-12-20T03:19:42Z</dc:date>
    </item>
  </channel>
</rss>

