Dashboards & Visualizations

JavaScript is not loading in my dashboard

GGrishma
Explorer

This is the JS I'm using to check if user ID is 7 digits

require([
"jquery",
"splunkjs/mvc/simplexml/ready!"
], function($,TableView, mvc, DashboardController){
var checkAndSetEvents = function() {
if($("#user_input").length) {
$("#user_input").change(function(event){
if(event.target.value && event.target.value.length > 7) {
$(".btn.btn-primary.submit").removeAttr("disabled");
} else {
$(".btn.btn-primary.submit").attr("disabled", "disabled");
}
});
} else {
setTimeout(checkAndSetEvents, 500);
}
}
checkAndSetEvents();

});

0 Karma

ololdach
Builder

Hi,
to include the script in your dashboard, please check the following:

  • You have included it in your dashboard's simpleXML form tag: <form script="myfile.js"> ... </form>
  • The .js file name is relative to the $SPLUNKDIR/etc/apps/<appname>/appserver/static and the file is in the right place
  • The file has read permissions for the splunk process user
  • You have cleared or disabled your local browser cache
  • You have reloaded the server settings and cleared the caches: https://yourserver:yourport/en-GB/debug/refresh and https://yourserver:yourport/en-GB/_bump

If it still doesn't work, maybe you could post your simpleXML and a little more details.
Hope it helps
Oliver

0 Karma

GGrishma
Explorer

yes I have added my js in $SPLUNKDIR/etc/apps//appserver/static and it is readable, yet its not working.

Add New User

<input type="text" token="user">
<label>Enter User ID</label>

Select Roles
All

 <query>| rest /services/authorization/roles splunk_server="local" | fields title | rename title as roles | mvexpand roles | dedup roles | sort + roles</query>
 <earliest>-1d@d</earliest>
 <latest>now</latest>

roles
roles

 <search>

|script add_user "$user$" $roles$
-1d@d
now

 </panel>
0 Karma

GGrishma
Explorer

Its called in the dashboard as below

User check

<input id="user_input" type="text" token="user">
  <label>Enter User ID</label>
</input>

.........................
.........................

0 Karma

GGrishma
Explorer

@DavidHourani : This is my dashboard, I need to enable the submit button only when 7 digits are entered in textbox for user id.

Add New User

<input type="text" token="user">
  <label>Enter User Bank ID</label>
</input>
<input type="multiselect" token="roles" searchWhenChanged="false">
  <label>Select Roles</label>
  <choice value="*">All</choice>
  <search>
    <query>| rest /services/authorization/roles splunk_server="local" | fields title | rename title as roles | mvexpand roles | dedup roles | sort + roles</query>
    <earliest>-1d@d</earliest>
    <latest>now</latest>
  </search>
  <fieldForLabel>roles</fieldForLabel>
  <fieldForValue>roles</fieldForValue>
</input>


<panel>
    <search>
<query>|script add_user "$user$" $roles$</query>
<earliest>-1d@d</earliest>
<latest>now</latest>

</panel>
0 Karma

DavidHourani
Super Champion

Hi @GGrishma,

Could you please share your dashboard ?

Also have a look at some previous answers on how to setup JS on the XML dashboard. Could be a good idea to start with a simple alert before moving to another function :
https://answers.splunk.com/answers/586958/how-do-i-add-javascript-to-a-splunk-dashboard.html

Cheers,
David

0 Karma

GGrishma
Explorer

I have called the js in my dashboard
@DavidHourani : This is my dashboard, I need to enable the submit button only when 7 digitd are entered in textbox for user id.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...

Keep the Learning Going with the New Best of .conf Hub

Hello Splunkers, With .conf26 getting closer, there’s already a lot of excitement building around this year’s ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...