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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...