<?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 Custom javascript doesn't work in Splunk Enterprise</title>
    <link>https://community.splunk.com/t5/Splunk-Enterprise/Custom-javascript-doesn-t-work/m-p/702313#M20561</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;i am trying to use custom javascript file to customize some button actions in my dashboard, but it doesn't work and i don't know why. I'm using the last version of Splunk enterprise&lt;/P&gt;&lt;P&gt;My custom script is in the folder&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;$SPLUNK_HOME/etc/apps/app_name/&lt;/STRONG&gt;&lt;STRONG&gt;appserver/static/.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I have&amp;nbsp; tried to restart Splunk web, use the bumps button but nothing works.&lt;/P&gt;&lt;P&gt;Can anyone help me?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Simple xml dashboard code&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;form version="1.1" theme="dark" script="button.js"&amp;gt;
  &amp;lt;search&amp;gt;
    &amp;lt;query&amp;gt;
      
      | makeresults | eval field1="test", field2="test1", field3="lll", field4="sgsgsg"
    &amp;lt;/query&amp;gt;
    &amp;lt;earliest&amp;gt;&amp;lt;/earliest&amp;gt;
    &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
    &amp;lt;done&amp;gt;
      &amp;lt;set token="field1"&amp;gt;$result.field1$&amp;lt;/set&amp;gt;
      &amp;lt;set token="field2"&amp;gt;$result.field2$&amp;lt;/set&amp;gt;
      &amp;lt;set token="field3"&amp;gt;$result.field3$&amp;lt;/set&amp;gt;
      &amp;lt;set token="field4"&amp;gt;$result.field4$&amp;lt;/set&amp;gt;
    &amp;lt;/done&amp;gt;
  &amp;lt;/search&amp;gt;
  &amp;lt;label&amp;gt;stacked_inputs&amp;lt;/label&amp;gt;
  &amp;lt;fieldset submitButton="false" autoRun="true"&amp;gt;&amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;title&amp;lt;/title&amp;gt;
      &amp;lt;input id="test_input1" type="text" token="field1"&amp;gt;
        &amp;lt;label&amp;gt;field1&amp;lt;/label&amp;gt;
        &amp;lt;default&amp;gt;$field1$&amp;lt;/default&amp;gt;
        &amp;lt;initialValue&amp;gt;$field1$&amp;lt;/initialValue&amp;gt;
      &amp;lt;/input&amp;gt;
      &amp;lt;input id="test_input2" type="text" token="field2"&amp;gt;
        &amp;lt;label&amp;gt;field2&amp;lt;/label&amp;gt;
        &amp;lt;default&amp;gt;$field2$&amp;lt;/default&amp;gt;
        &amp;lt;initialValue&amp;gt;$field2$&amp;lt;/initialValue&amp;gt;
      &amp;lt;/input&amp;gt;
      &amp;lt;html&amp;gt;
            
            &amp;lt;style&amp;gt;
              #test_input2 {
                  padding-left: 30px !important; 
                  
                  }
              
              
            &amp;lt;/style&amp;gt;
            
          &amp;lt;/html&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;input id="test_input3" type="text" token="field3"&amp;gt;
        &amp;lt;label&amp;gt;field3&amp;lt;/label&amp;gt;
        &amp;lt;default&amp;gt;$field3$&amp;lt;/default&amp;gt;
        &amp;lt;initialValue&amp;gt;$field3$&amp;lt;/initialValue&amp;gt;
      &amp;lt;/input&amp;gt;
      &amp;lt;input id="test_input4" type="text" token="field4"&amp;gt;
        &amp;lt;label&amp;gt;field4&amp;lt;/label&amp;gt;
        &amp;lt;default&amp;gt;$field4$&amp;lt;/default&amp;gt;
        &amp;lt;initialValue&amp;gt;$field4$&amp;lt;/initialValue&amp;gt;
      &amp;lt;/input&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
        &amp;lt;form&amp;gt;
         &amp;lt;div&amp;gt;
           &amp;lt;div&amp;gt;
            &amp;lt;label&amp;gt;Password&amp;lt;/label&amp;gt;
            &amp;lt;input type="text" value="$field4$"/&amp;gt;
            &amp;lt;br/&amp;gt;
            &amp;lt;input type="password" id="exampleInputPassword1" placeholder="Password"/&amp;gt;
          &amp;lt;/div&amp;gt;
           &amp;lt;/div&amp;gt;
           &amp;lt;button type="submit" class="btn btn-primary"&amp;gt;Submit&amp;lt;/button&amp;gt;
           &amp;lt;/form&amp;gt;
           &amp;lt;button onclick="test()"&amp;gt;Back&amp;lt;/button&amp;gt;
           &amp;lt;button onclick="test1()"&amp;gt;Back1&amp;lt;/button&amp;gt;
           &amp;lt;button id="back" data-param="test"&amp;gt;Back2&amp;lt;/button&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;Javascript code&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="catta99_0-1729346067923.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/33145i3A092381051ACB59/image-size/medium?v=v2&amp;amp;px=400" role="button" title="catta99_0-1729346067923.png" alt="catta99_0-1729346067923.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;As you can see i have tried different methods&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 19 Oct 2024 13:57:30 GMT</pubDate>
    <dc:creator>catta99</dc:creator>
    <dc:date>2024-10-19T13:57:30Z</dc:date>
    <item>
      <title>Custom javascript doesn't work</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Custom-javascript-doesn-t-work/m-p/702313#M20561</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;i am trying to use custom javascript file to customize some button actions in my dashboard, but it doesn't work and i don't know why. I'm using the last version of Splunk enterprise&lt;/P&gt;&lt;P&gt;My custom script is in the folder&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;$SPLUNK_HOME/etc/apps/app_name/&lt;/STRONG&gt;&lt;STRONG&gt;appserver/static/.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I have&amp;nbsp; tried to restart Splunk web, use the bumps button but nothing works.&lt;/P&gt;&lt;P&gt;Can anyone help me?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Simple xml dashboard code&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;form version="1.1" theme="dark" script="button.js"&amp;gt;
  &amp;lt;search&amp;gt;
    &amp;lt;query&amp;gt;
      
      | makeresults | eval field1="test", field2="test1", field3="lll", field4="sgsgsg"
    &amp;lt;/query&amp;gt;
    &amp;lt;earliest&amp;gt;&amp;lt;/earliest&amp;gt;
    &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
    &amp;lt;done&amp;gt;
      &amp;lt;set token="field1"&amp;gt;$result.field1$&amp;lt;/set&amp;gt;
      &amp;lt;set token="field2"&amp;gt;$result.field2$&amp;lt;/set&amp;gt;
      &amp;lt;set token="field3"&amp;gt;$result.field3$&amp;lt;/set&amp;gt;
      &amp;lt;set token="field4"&amp;gt;$result.field4$&amp;lt;/set&amp;gt;
    &amp;lt;/done&amp;gt;
  &amp;lt;/search&amp;gt;
  &amp;lt;label&amp;gt;stacked_inputs&amp;lt;/label&amp;gt;
  &amp;lt;fieldset submitButton="false" autoRun="true"&amp;gt;&amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;title&amp;lt;/title&amp;gt;
      &amp;lt;input id="test_input1" type="text" token="field1"&amp;gt;
        &amp;lt;label&amp;gt;field1&amp;lt;/label&amp;gt;
        &amp;lt;default&amp;gt;$field1$&amp;lt;/default&amp;gt;
        &amp;lt;initialValue&amp;gt;$field1$&amp;lt;/initialValue&amp;gt;
      &amp;lt;/input&amp;gt;
      &amp;lt;input id="test_input2" type="text" token="field2"&amp;gt;
        &amp;lt;label&amp;gt;field2&amp;lt;/label&amp;gt;
        &amp;lt;default&amp;gt;$field2$&amp;lt;/default&amp;gt;
        &amp;lt;initialValue&amp;gt;$field2$&amp;lt;/initialValue&amp;gt;
      &amp;lt;/input&amp;gt;
      &amp;lt;html&amp;gt;
            
            &amp;lt;style&amp;gt;
              #test_input2 {
                  padding-left: 30px !important; 
                  
                  }
              
              
            &amp;lt;/style&amp;gt;
            
          &amp;lt;/html&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;input id="test_input3" type="text" token="field3"&amp;gt;
        &amp;lt;label&amp;gt;field3&amp;lt;/label&amp;gt;
        &amp;lt;default&amp;gt;$field3$&amp;lt;/default&amp;gt;
        &amp;lt;initialValue&amp;gt;$field3$&amp;lt;/initialValue&amp;gt;
      &amp;lt;/input&amp;gt;
      &amp;lt;input id="test_input4" type="text" token="field4"&amp;gt;
        &amp;lt;label&amp;gt;field4&amp;lt;/label&amp;gt;
        &amp;lt;default&amp;gt;$field4$&amp;lt;/default&amp;gt;
        &amp;lt;initialValue&amp;gt;$field4$&amp;lt;/initialValue&amp;gt;
      &amp;lt;/input&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
        &amp;lt;form&amp;gt;
         &amp;lt;div&amp;gt;
           &amp;lt;div&amp;gt;
            &amp;lt;label&amp;gt;Password&amp;lt;/label&amp;gt;
            &amp;lt;input type="text" value="$field4$"/&amp;gt;
            &amp;lt;br/&amp;gt;
            &amp;lt;input type="password" id="exampleInputPassword1" placeholder="Password"/&amp;gt;
          &amp;lt;/div&amp;gt;
           &amp;lt;/div&amp;gt;
           &amp;lt;button type="submit" class="btn btn-primary"&amp;gt;Submit&amp;lt;/button&amp;gt;
           &amp;lt;/form&amp;gt;
           &amp;lt;button onclick="test()"&amp;gt;Back&amp;lt;/button&amp;gt;
           &amp;lt;button onclick="test1()"&amp;gt;Back1&amp;lt;/button&amp;gt;
           &amp;lt;button id="back" data-param="test"&amp;gt;Back2&amp;lt;/button&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;Javascript code&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="catta99_0-1729346067923.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/33145i3A092381051ACB59/image-size/medium?v=v2&amp;amp;px=400" role="button" title="catta99_0-1729346067923.png" alt="catta99_0-1729346067923.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;As you can see i have tried different methods&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Oct 2024 13:57:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Custom-javascript-doesn-t-work/m-p/702313#M20561</guid>
      <dc:creator>catta99</dc:creator>
      <dc:date>2024-10-19T13:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: Custom javascript doesn't work</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Custom-javascript-doesn-t-work/m-p/702330#M20562</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/272819"&gt;@catta99&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;In your JavaScript source, you can use jQuery selectors to attach a click event handler to an object.&lt;/P&gt;&lt;P&gt;In this example, I define a button with id="button1" in button_test.xml and attach a click event handler in button_test.js:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!-- button_test.xml --&amp;gt;
&amp;lt;dashboard version="1.1" theme="light" script="button_test.js"&amp;gt;
  &amp;lt;label&amp;gt;button_test&amp;lt;/label&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
        &amp;lt;button id="button1"&amp;gt;Button 1&amp;lt;/button&amp;gt;
      &amp;lt;/html&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;&lt;/LI-CODE&gt;&lt;LI-CODE lang="javascript"&gt;// button_test.js
require([
    "jquery",
    "splunkjs/mvc",
    "splunkjs/mvc/simplexml/ready!"
], function($, mvc) {
    $("#button1").on("click", function() {
        alert("Button 1 clicked.");
    });
});&lt;/LI-CODE&gt;&lt;P&gt;When button1 is clicked, the browser displays a dialog box with the message "Button 1 clicked."&lt;/P&gt;&lt;P&gt;SplunkJS is documented at&amp;nbsp;&lt;A href="https://dev.splunk.com/enterprise/docs/developapps/visualizedata/usewebframework/" target="_blank"&gt;https://dev.splunk.com/enterprise/docs/developapps/visualizedata/usewebframework/&lt;/A&gt;, where you can find example JavaScript templates.&lt;/P&gt;&lt;P&gt;RequireJS is documented at&amp;nbsp;&lt;A href="https://requirejs.org/docs/api.html#jsfiles," target="_blank"&gt;https://requirejs.org/docs/api.html#jsfiles,&lt;/A&gt;&amp;nbsp;but its use is limited to the require([...], function(...) {}); shown above.&lt;/P&gt;&lt;P&gt;jQuery selectors are documented at&amp;nbsp;&lt;A href="https://api.jquery.com/category/selectors/" target="_blank"&gt;https://api.jquery.com/category/selectors/&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;The jQuery click event is documented at&amp;nbsp;&lt;A href="https://api.jquery.com/click/" target="_blank"&gt;https://api.jquery.com/click/&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Oct 2024 17:20:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Custom-javascript-doesn-t-work/m-p/702330#M20562</guid>
      <dc:creator>tscroggins</dc:creator>
      <dc:date>2024-10-20T17:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Custom javascript doesn't work</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Custom-javascript-doesn-t-work/m-p/702393#M20579</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/49493"&gt;@tscroggins&lt;/a&gt;&amp;nbsp;, for your answer.&lt;/P&gt;&lt;P&gt;But i still have some big problem with javascript, because sometimes Splunk web did not load the code, sometimes&amp;nbsp; the code didn't work and some times works&amp;nbsp;&lt;SPAN&gt;without&amp;nbsp;changing it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I have red the documentation, i use the refresh button (&lt;A target="_blank" rel="noopener"&gt;http://&amp;lt;ip:port&amp;gt;/debug/refresh&lt;/A&gt;), i'm using my browser in&amp;nbsp;&lt;SPAN&gt;incognito mode but nothing, i restar splunk web when i add a new js file. I even tried to fully restart splunk&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank for your help&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2024 17:24:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Custom-javascript-doesn-t-work/m-p/702393#M20579</guid>
      <dc:creator>catta99</dc:creator>
      <dc:date>2024-10-21T17:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Custom javascript doesn't work</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Custom-javascript-doesn-t-work/m-p/702642#M20597</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/272819"&gt;@catta99&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;To clear the server-side cache, restart splunkweb as you have done:&lt;/P&gt;&lt;P&gt;$SPLUNK_HOME/splunk/bin/splunk restart splunkweb&lt;/P&gt;&lt;P&gt;To clear the client-side cache, use your browser's cache functions or temporarily disable caching in your browser's dev tools.&lt;/P&gt;&lt;P&gt;To prevent splunkweb from caching source files during development, you can disable caching in web.conf and restart Splunk:&amp;nbsp;&lt;/P&gt;&lt;P&gt;# $SPLUNK_HOME/etc/system/local/web.conf&lt;BR /&gt;[settings]&lt;BR /&gt;cacheBytesLimit = 0&lt;/P&gt;&lt;P&gt;The example I provided can be expanded as needed. If you're still having issues after clearing all caches, reply with a reduced SimpleXML and JavaScript example, and we'll take another look.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 00:41:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Custom-javascript-doesn-t-work/m-p/702642#M20597</guid>
      <dc:creator>tscroggins</dc:creator>
      <dc:date>2024-10-24T00:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: Custom javascript doesn't work</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Custom-javascript-doesn-t-work/m-p/702666#M20602</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/49493"&gt;@tscroggins&lt;/a&gt;, thanks for your answer,&lt;/P&gt;&lt;P&gt;in the documentation i have found this configuration:&lt;/P&gt;&lt;P&gt;minify_js = False&lt;/P&gt;&lt;P&gt;js_no_cache = True&lt;/P&gt;&lt;P&gt;cacheEntriesLimit = 0&lt;/P&gt;&lt;P&gt;cacheBytesLimit = 0&lt;/P&gt;&lt;P&gt;enableWebDebug = True&lt;/P&gt;&lt;P&gt;and it works.&lt;/P&gt;&lt;P&gt;Sometimes not but i go to /debug/refresh and click the refresh button and splunk loads the new version of the js file.&lt;/P&gt;&lt;P&gt;But if you have a dashboard like that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;dashboard script="MyScript.js"&amp;gt;
&amp;lt;search id="MySearch"&amp;gt;
&amp;lt;query&amp;gt;
query that take some time
&amp;lt;/query&amp;gt;
&amp;lt;/search&amp;gt;
&amp;lt;row&amp;gt;
&amp;lt;panel&amp;gt;
&amp;lt;hmtl&amp;gt; &amp;lt;button id="btn"&amp;gt;Button &amp;lt;/button&amp;gt;
&amp;lt;/html&amp;gt;
&amp;lt;/panel&amp;gt;
&amp;lt;/row&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//MyScript


require(["jquery", "splunkjs/mvc", "splunkjs/mvc/simplexml/ready!"], function($, mvc) {

$("#btn").on("click", function() {

// js code
});
});​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Splunk will not load the Jquery part, but if you go on "edit"-&amp;gt;"source"-&amp;gt;"cancel" without modifiyng anything in the dashboard source code the javascript code works.&lt;/P&gt;&lt;P&gt;So the problem maybe is caused because the search (id="MySearch") in the dashboard is executed in an async way?&lt;/P&gt;&lt;P&gt;I have read some posts on this topic but i didn't find any solution&lt;/P&gt;&lt;P&gt;I have tried&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require(["jquery", "splunkjs/mvc", "splunkjs/mvc/simplexml/ready!"], function($, mvc) {
$("#MySearch").on("search:done", function(){
$("#btn").on("click", function() {

// js code
});
});​
});&lt;/LI-CODE&gt;&lt;P&gt;but nothing&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 06:59:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Custom-javascript-doesn-t-work/m-p/702666#M20602</guid>
      <dc:creator>catta99</dc:creator>
      <dc:date>2024-10-24T06:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: Custom javascript doesn't work</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Custom-javascript-doesn-t-work/m-p/703406#M20672</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/272819"&gt;@catta99&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;You probably want to start with buttons disabled and then enabled them when the dashboard's async searches are done. You can use SplunkJS to attach search:done event handlers to your searches (see below).&lt;/P&gt;&lt;P&gt;A complex dashboard (multiple searches, multiple buttons, etc.) may require a more complex solution. You can find more information in the SplunkJS documentation or more generally, in your favorite web development resources (or AI stack, if you use one).&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!-- button_test.xml --&amp;gt;
&amp;lt;dashboard version="1.1" theme="light" script="button_test.js"&amp;gt;
  &amp;lt;label&amp;gt;button_test&amp;lt;/label&amp;gt;
  &amp;lt;search id="search1"&amp;gt;
    &amp;lt;query&amp;gt;| stats count&amp;lt;/query&amp;gt;
    &amp;lt;earliest&amp;gt;-24h&amp;lt;/earliest&amp;gt;
    &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
  &amp;lt;/search&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
        &amp;lt;!-- assign a value to the disabled attribute to pass SplunkWeb's Simple XML validation --&amp;gt;
        &amp;lt;button id="button1" disabled="disabled"&amp;gt;Button 1&amp;lt;/button&amp;gt;
      &amp;lt;/html&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;&lt;/LI-CODE&gt;&lt;LI-CODE lang="javascript"&gt;// button_test.js
require([
    "jquery",
    "splunkjs/mvc",
    "splunkjs/mvc/simplexml/ready!"
], function($, mvc) {
    search1 = splunkjs.mvc.Components.get("search1");

    search1.on("search:done", function(properties) {
      $("#button1").prop("disabled", false);
    });

    $("#button1").on("click", function() {
        alert("Button 1 clicked.");
    });
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Nov 2024 16:50:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Custom-javascript-doesn-t-work/m-p/703406#M20672</guid>
      <dc:creator>tscroggins</dc:creator>
      <dc:date>2024-11-02T16:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: Custom javascript doesn't work</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Custom-javascript-doesn-t-work/m-p/703460#M20681</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/272819"&gt;@catta99&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please check below code&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function test() {
    console.log("in test");
}

require([
    "jquery",
    "splunkjs/mvc",
    "splunkjs/mvc/simplexml/ready!"
], function($, mvc) {


    console.log("hello 2");
    function test1() {
        console.log("in test1");
    }
    
    $(document).ready(function () {
        $("#back").click(function(){
            alert("button");
            var param = $(this).data("param");
            console.log(param); 
            console.log("click"); 
            history.back();
        });
        $("#backtest").click(function(){
            test();
            alert("Back");
        });
        $("#back1test").click(function(){
            test1();
            alert("Back1");
        });
    })
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Splunk Web Framework works little different from regular or Native Jquery/Javascript behaviour specially on HTML element. So when you write&lt;/P&gt;&lt;P&gt;&amp;lt;button onclick="test()"&amp;gt;Back&amp;lt;/button&amp;gt;&lt;BR /&gt;&amp;lt;button onclick="test1()"&amp;gt;Back1&amp;lt;/button&amp;gt;&lt;/P&gt;&lt;P&gt;It may not work bcoz when you run the dashboard, the Dashboard XML is rendering into complied version of JS, CSS and HTML. After all this process it will allow developer to add custom JS, CSS and even custom components through custom JS like button_test.js. So all customisation and the element event handleling will be define in this JS only.&lt;/P&gt;&lt;P&gt;Suggestion: Using below code is not best practive. Just code what you want instead of&lt;/P&gt;&lt;P&gt;this.history.back();&lt;/P&gt;&lt;P&gt;I hope this will help you.&lt;/P&gt;&lt;P&gt;Let me know if you need further help on this.&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;An upvote would be appreciated if any of my replies help you solve the problem or gain knowledge.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2024 04:59:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Custom-javascript-doesn-t-work/m-p/703460#M20681</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2024-11-04T04:59:20Z</dc:date>
    </item>
  </channel>
</rss>

