Splunk Search

How can I get external JavaScript framework app to wait until the search has completed before executing additional code?

jedatt01
Builder

I need my app to wait until the search has completed before it executes additional code. I'm using the following method to see when my search has completed......but I can't figure out how stop additional code from running until this on method is complete.

myResults = [];

search1.on("search:done", function(properties) {
    myResults = search1.data("results", {count: 0});
});

After this, I want to iterate through the myResults.data().rows and run additional code.

Please help!

0 Karma

renjith_nair
Legend

In html dashboard we do like this

            search1.on('search:done', function(properties) {
              var resultCount=properties.content.resultCount;           
                //Insert only if no record exists for same 
                if(resultCount < 1) { 
                    saveRecord(record);
                }

                //If record already exists, update it. But get a confirmation from user
                else {
                    var question='Record already exists Do you want to update?';
                    if (confirm(question)) {
                      updateRecord();
                    }   
                }
            });

it might help!

Happy Splunking!
Get Updates on the Splunk Community!

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

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...