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!

Splunk APM & RUM | Upcoming Planned Maintenance

There will be planned maintenance of the streaming infrastructure for Splunk APM and Splunk RUM in the coming ...

Part 2: Diving Deeper With AIOps

Getting the Most Out of Event Correlation and Alert Storm Detection in Splunk IT Service Intelligence   Watch ...

User Groups | Upcoming Events!

If by chance you weren't already aware, the Splunk Community is host to numerous User Groups, organized ...