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
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...