All Apps and Add-ons

Search is not running from JS

Champion

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

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