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!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...