<?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: Javascript in Dashboard not working in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-in-Dashboard-not-working/m-p/569642#M46796</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/127939"&gt;@kamlesh_vaghela&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Interesting behavior, i pasted your Code and it worked, but the input only set the token once.&lt;/P&gt;&lt;P&gt;When i type 20 in the input and press the Button first time, the token $randInt$ get set to 20, but when i change the input from 20 to 10 and press the button again nothing happens.&lt;/P&gt;&lt;P&gt;I changed the Line where the token get set to&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;   tokens.set("randInt", console.log(tokens.get("field1")));&lt;/LI-CODE&gt;&lt;P&gt;to test something, every buttonclick write a log with the current value from the input.&lt;BR /&gt;Is it a "feature" from Splunk to set the token just one time?&lt;BR /&gt;I Also tried to unset the token before setting it again, also just one time set.&lt;/P&gt;</description>
    <pubDate>Tue, 05 Oct 2021 06:07:12 GMT</pubDate>
    <dc:creator>TheEggi98</dc:creator>
    <dc:date>2021-10-05T06:07:12Z</dc:date>
    <item>
      <title>Javascript in Dashboard not working</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-in-Dashboard-not-working/m-p/569524#M46780</link>
      <description>&lt;P&gt;I tried to add a simple JS to a dashboard but nothing i tried works.&lt;BR /&gt;I have Splunk&amp;nbsp;&lt;SPAN&gt;8.2.1 single instance on Windows.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The script is in&amp;nbsp;C:\Program Files\Splunk\etc\apps\&amp;lt;appname&amp;gt;\appserver\static&lt;/P&gt;&lt;P&gt;i restartet the splunk service several times and clicked the bump button several times.&lt;BR /&gt;JS is active in my browser and the cache got cleared several times too.&lt;/P&gt;&lt;P&gt;When i go to&amp;nbsp;&lt;A href="https://community.splunk.com/" target="_blank"&gt;http://127.0.0.1:8000/de-DE/app/&amp;lt;appname&amp;gt;/&amp;lt;dashboardname&amp;gt;/&amp;lt;scriptname&amp;gt;&lt;/A&gt;&amp;nbsp;i just get {}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;My Dashboard:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;form script="btnclick.js"&amp;gt;
  &amp;lt;label&amp;gt;JS Test&amp;lt;/label&amp;gt;
  &amp;lt;init&amp;gt;
  &amp;lt;/init&amp;gt;
  &amp;lt;fieldset submitButton="false"&amp;gt;
    &amp;lt;input type="text" token="field1"&amp;gt;
      &amp;lt;label&amp;gt;field1&amp;lt;/label&amp;gt;
      &amp;lt;default&amp;gt;$randInt$&amp;lt;/default&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
          &amp;lt;button id="rand" class="btn btn-primary"&amp;gt;Random&amp;lt;/button&amp;gt;
          &amp;lt;p&amp;gt;
            $randInt$
          &amp;lt;/p&amp;gt;
      &amp;lt;/html&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;My JS:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require(
	[
		"splunkjs/mvc",
		"splunkjs/mvc/simplexml/ready!"
	], function(mvc) {
		var tokens = mvc.Components.get("default");
		console.log("Test");
		$('#rand').on("click",function(){
			tokens.set("randInt", 2);
		});
	}
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why does it not work?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 09:52:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-in-Dashboard-not-working/m-p/569524#M46780</guid>
      <dc:creator>TheEggi98</dc:creator>
      <dc:date>2021-10-04T09:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript in Dashboard not working</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-in-Dashboard-not-working/m-p/569572#M46791</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/238005"&gt;@TheEggi98&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code looks good.&amp;nbsp;Even&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A target="_blank" rel="nofollow noopener noreferrer"&gt;http://127.0.0.1:8000/de-DE/app/&amp;lt;appname&amp;gt;/&amp;lt;dashboardname&amp;gt;/&amp;lt;scriptname&amp;gt;&lt;/A&gt;&amp;nbsp;working fine for me.&lt;/P&gt;&lt;P&gt;Can you please try below version in your instance?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require([
    'splunkjs/mvc',
    'jquery',
    "splunkjs/mvc/simplexml/ready!"
], function(mvc, $) {
    var tokens = mvc.Components.get("default");
    console.log("Test");
    $(document).ready(function() {
        $('#rand').on("click", function() {
            console.log(tokens.get("field1"))
            tokens.set("randInt", tokens.get("field1"));
        });
    })
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thanks&lt;BR /&gt;KV&lt;BR /&gt;▄︻̷̿┻̿═━一 &amp;nbsp; &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 15:34:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-in-Dashboard-not-working/m-p/569572#M46791</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2021-10-04T15:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript in Dashboard not working</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-in-Dashboard-not-working/m-p/569642#M46796</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/127939"&gt;@kamlesh_vaghela&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Interesting behavior, i pasted your Code and it worked, but the input only set the token once.&lt;/P&gt;&lt;P&gt;When i type 20 in the input and press the Button first time, the token $randInt$ get set to 20, but when i change the input from 20 to 10 and press the button again nothing happens.&lt;/P&gt;&lt;P&gt;I changed the Line where the token get set to&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;   tokens.set("randInt", console.log(tokens.get("field1")));&lt;/LI-CODE&gt;&lt;P&gt;to test something, every buttonclick write a log with the current value from the input.&lt;BR /&gt;Is it a "feature" from Splunk to set the token just one time?&lt;BR /&gt;I Also tried to unset the token before setting it again, also just one time set.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Oct 2021 06:07:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-in-Dashboard-not-working/m-p/569642#M46796</guid>
      <dc:creator>TheEggi98</dc:creator>
      <dc:date>2021-10-05T06:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript in Dashboard not working</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-in-Dashboard-not-working/m-p/569711#M46803</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/238005"&gt;@TheEggi98&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have observed another thing, may be that will help you.&lt;/P&gt;&lt;P&gt;The Observation is regarding &lt;STRONG&gt;html&amp;nbsp;&lt;/STRONG&gt;panel.&lt;/P&gt;&lt;P&gt;"When any token been changed and reflected in &lt;STRONG&gt;HTML, it will&amp;nbsp;re-render the html&amp;nbsp;content and removed&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;previously&amp;nbsp;assigned events on any html element."&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;So Please try below code and let me know your observations as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;form script="a.js"&amp;gt;
  &amp;lt;label&amp;gt;JS Test&amp;lt;/label&amp;gt;
  &amp;lt;init&amp;gt;
  &amp;lt;/init&amp;gt;
  &amp;lt;fieldset submitButton="false"&amp;gt;
    &amp;lt;input type="text" token="field1"&amp;gt;
      &amp;lt;label&amp;gt;field1&amp;lt;/label&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
          &amp;lt;button id="rand" class="btn btn-primary"&amp;gt;Random&amp;lt;/button&amp;gt;
      &amp;lt;/html&amp;gt;
    &amp;lt;/panel&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
          &amp;lt;p&amp;gt;
            $randInt$
          &amp;lt;/p&amp;gt;
      &amp;lt;/html&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require([
    'underscore',
    'splunkjs/mvc',
    'jquery',
    "splunkjs/mvc/simplexml/ready!"
], function(_, mvc, $) {
    var tokens = mvc.Components.get("default");
    console.log("Test");
    $(document).ready(function() {
        console.log("Strt")
        $('#rand').on("click", function() {
            console.log("clicked")
            console.log(tokens.get("field1"))
            tokens.set("randInt", tokens.get("field1"));
            console.log(tokens.get("randInt"))
            console.log($('#rand'))
        });
    })
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;▄︻̷̿┻̿═━一 &amp;nbsp; &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Oct 2021 14:54:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-in-Dashboard-not-working/m-p/569711#M46803</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2021-10-05T14:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript in Dashboard not working</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-in-Dashboard-not-working/m-p/569730#M46806</link>
      <description>&lt;P&gt;Thats really good to know.&lt;/P&gt;&lt;P&gt;Now only the capabilities of JS can stop me from improving Dashboards &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Oct 2021 16:50:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-in-Dashboard-not-working/m-p/569730#M46806</guid>
      <dc:creator>TheEggi98</dc:creator>
      <dc:date>2021-10-05T16:50:17Z</dc:date>
    </item>
  </channel>
</rss>

