Splunk Search

Cannot access results of a Searchmanager in a for loop

New Member

I have a dashboard that should perform a dynamic number of searches. For this purpose I created a search manager, which receives new search strings via a For loop. Via an on-data listener I access the results of the search manager. If I have only one pass of the loop, I get the correct results, but already with two passes I get the result of the second search output twice. I have attached a minimal example of the problem here.

searchmanager = new SearchManager(…)
for (var i = 0; i < array.length; i++) {
     var search_string = "| makeresults | eval a=" + i + " | table a";

      searchmanager.settings.set("search", search_string);

     var results = searchmanager.data("results");

     searchmanager.on("search:done", function() {
           results.on("data", function() {
               if (results.data()) {
                    var fields = results.data().fields;
                    var rows = results.data().rows;



The output of the console is for an array of a length of two always twice an object with "1" as the result and not one time "0" and then "1" as one would expect. For an array of a length of one the result is an object with "0" as the result.

I suspect the on("data") listener because i checked the search string and everything and at any given point there is the difference of the value in the objects but as soon as I try to enter the result with the listener it only gives me the result with "1" in the row.

I also tried to put the results in an array and access the result object after that with no success.

I hope someone can help me and that the minimal example helps to explain my problem. Thank you very much.

0 Karma
Get Updates on the Splunk Community!

Devesh Logendran, Splunk, and the Singapore Cyber Conquest

At this year’s Splunk University, I had the privilege of chatting with Devesh Logendran, one of the winners in ...

There's No Place Like Chrome and the Splunk Platform

WATCH NOW!Malware. Risky Extensions. Data Exfiltration. End-users are increasingly reliant on browsers to ...

Customer Experience | Join the Customer Advisory Board!

Are you ready to take your Splunk journey to the next level? &#x1f680; We invite you to join our elite squad ...