Getting Data In

Loading custom javascript in custom app

JacobPN
Path Finder

Hi all,

I created a custom app from the "sample app" template. I put a application.js file in the appserver/static folder.
This file contains:

console.log("hello")

However, when I open the app, the message is not displayed in the console. I have restarted splunk, cleared my browser cache, and used the _bump endpoint. It seems that the javascript just is not getting loaded. What am I missing here? (my Splunk version is 7.2.0)

Thanks!

Tags (1)
0 Karma

vnravikumar
Champion

Hi @JacobPN

It has to work, just cross check whether you had included javascript in your dashboard. The following code works for me. To include advanced js just follow the comment given by @sdchakraborty

<dashboard script="application.js">
  <label>sampledashboard</label>
</dashboard>

application.js

console.log("this is to test javascript file");
0 Karma

JacobPN
Path Finder

Hi @vnravikumar,

Thank you for your comment. Do you know a way to achieve this at the home page of the application? So outside of any dashboards?
Thanks!

0 Karma

sdchakraborty
Contributor

you js need to wrap inside require call. something like below,

require([
'jquery',
'underscore',
'splunkjs/mvc',
'splunkjs/mvc/simplexml/ready!'
],
function($,_,mvc){
    console.log("test")
}
)

then in dashboard form tag you need to include the js file name like below,

<form script="youjsfile.js">

Sid

0 Karma

JacobPN
Path Finder

Hi Sid,

Thanks for the help. Will this work in the home page of the appllcation as well? So not only in dashboards? I'm not sure were to reference the js-file in that case.
Thanks!

0 Karma

sdchakraborty
Contributor

Hi Jacob,

How you developed the application home page? Is it written in html? You can refer ths js in similar way in html page as well, using script tag.

http://web.simmons.edu/~grabiner/comm244/weeknine/including-javascript.html

Sid

0 Karma

JacobPN
Path Finder

Hi Sid,

I simply created a new app, from the sample app template. So:
"Manage apps" > "Create app" and then choose the template "sample_app" and click save.
Subsequently I placed the mentioned "applications.js" in the appserver/static folder of this app. There is no index.html or anything like that in that folder, where I could place the script tag.

Jacob

0 Karma

sdchakraborty
Contributor

Ahh I got it. To see how the java script works you need to create a dashboard in your app. There in the form tag you can add script.

https://docs.splunk.com/Documentation/Splunk/7.2.4/SearchTutorial/Createnewdashboard

And please ignore my previous comment as I dont want to confuse you. Follow whatever ma or @vnravikumar posted yesterday.

Sid

0 Karma

JacobPN
Path Finder

I tested it on a dashboard and that works. However, now I want it the work on the app home page. So I want it to log "hello" to the console, on the app homepage. Any ideas?

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...