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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...