All Apps and Add-ons

Search is not running from JS

thambisetty
SplunkTrust
SplunkTrust

Hi,

i have below JS used in dashboard

require([
    'underscore',
    'backbone',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/searchmanager',
    //'../app/ek_app_phishing/components/ModalView',
    'splunkjs/mvc/simplexml/ready!'
//], function(_, Backbone, $, mvc, TableView, SearchManager, ModalView) {
], function(_, Backbone, $, mvc, SearchManager) {

                console.log('script called');
                var tokens = mvc.Components.get("default");
                var sendEmail = mvc.Components.get("sendEmail");
                console.log(sendEmail);
                var existingToken=tokens.get("tokenSubmitClicked");
                console.log(existingToken);

                var sendEmail = new SearchManager({
                id: "sendEmail",
                autostart: false,
                search : "|makeresults | eval dummyToken=\"$tokenSubmitClicked$\" | sendalert notablealerts param.script=\"phishing_email_latest_2708.py\""
                });

                $(document).find('.dashboard-body').append('<button id="sndemlntfcn" class="btn btn-primary">Send Email Notification</button>');

                $(document).on('click','#sndemlntfcn',function(e) {
                        e.preventDefault();
                        console.log('button clicked');
                        tokens.set("tokenSubmitClicked", "true");
                        var afterSetToken=tokens.get("tokenSubmitClicked");
                        console.log(afterSetToken);
                        sendEmail.startSearch();
                        console.log('Email have been sent');
                        $(document).find("#EmailStatus").html("<span class=\"success\">Emails have been sent!</span>");
                });

});

Getting below error in Browser console:

Uncaught TypeError: sendEmail.startSearch is not a function
    at HTMLButtonElement.eval (eval at globalEval (common.js:14), <anonymous>:38:27)
    at HTMLDocument.dispatch (common.js:25)
    at HTMLDocument.elemData.handle (common.js:25)

please help me to run search using button.

————————————
If this helps, give a like below.
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@thambisetty

Just remove or comment 'splunkjs/mvc/tableview' in require function. Your SearchManager is taking tableview object.

 require([
     'underscore',
     'backbone',
     'jquery',
     'splunkjs/mvc',
   //  'splunkjs/mvc/tableview',
     'splunkjs/mvc/searchmanager',
     //'../app/ek_app_phishing/components/ModalView',
     'splunkjs/mvc/simplexml/ready!'
 //], function(_, Backbone, $, mvc, TableView, SearchManager, ModalView) {
 ], function(_, Backbone, $, mvc, SearchManager) {

OR add TableView in function,

Thanks

0 Karma
Get Updates on the Splunk Community!

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, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...