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 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...