Alerting

Loading JavaScript in Custom Alert Action HTML File in Splunk?

rick-exp54
New Member

Hello everyone! I've created a custom alert action with an HTML file located at Splunk\etc\apps\my-app\local\data\ui\alerts\index.html, and my JavaScript and CSS files are in Splunk\etc\apps\my-app\appserver\static\index.js. My goal is to dynamically add fields to a form using JavaScript inside my HTML file. I'm encountering challenges with loading the JavaScript due to potential security concerns in Splunk apps. Despite this, I'm looking for a solution to implement this small functionality. Any assistance would be greatly appreciated.
Thank you for your help!

HTML code - 

<!DOCTYPE html>
<html>
<head>
<title>Custom Alert Action</title>
<script></script>
<script src="../../../../appserver/static/index.js"></script>
</head>
<body>
<h1>Custom Alert Action</h1>
<button id="performActionBtn">Perform Action</button>
</body>
</html>



JS code -

require([
    'jquery',
     'splunkjs/mvc',
     'splunkjs/mvc/simplexml/ready!'
], function($, mvc) {

console.log('js loaded successfully');
    function createfunction() {
        alert('js loaded successfully!');
    }
    $(document).ready(function() {
console.log('js loaded successfully');
        $('#performActionBtn').click(function(event) {
            event.preventDefault(); 
            createfunction(); 
        });
    });
});


hi dear @avikramengg, I saw a similar question you asked earlier. Have you found a solution? If so, could you please advise me as well? Thanks!

Labels (1)
0 Karma
Get Updates on the Splunk Community!

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...