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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...