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!

---
What goes around comes around. If it helps, hit it with Karma 🙂
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...