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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...