Splunk Search

Searchmanager cannot reuse in for loop in HTML dashboard

chrismok
Path Finder

Currently, my dashboard is basic on the number of the source
and generate the number of chart or table.

The structure is looks like that

   var search0=new searchmanager(......)

    search0.data('result').on('data',function(properties){
  //sudo code
   add  search0.data('result').data.row to source_array;
 //sudo code
    for(var row=1; row<=source_array.length; row++)
    {
       var search1=new searchmanager(....... "id":"search1".....)
        search1.data('result').on('data',function(properties){
            BuildInfo(search1.data('results').data().rows);
         }

    }
}

When I run, it. The first char can be generated, but loop to the second round. browser return an error message
Uncaught Error: Already have instance with id: search1 (mvc.js:6)
Uncaught TypeError: Cannot read property 'rows' of undefined (my javascript file, refer to line 10)

For the first error, I have a temp solution which modify the code which add the variable id for avoid the search id redundant

   var id=0;
    var search0=new searchmanager(......)

    search0.data('result').on('data',function(properties){
//sudo code
   add  search0.data('result').data.row to source_array;
 //sudo code
    for(var row=1; row<=source_array.length; row++)
    {
       var search1=new searchmanager(....... "id":"search"+(++id).....)
        search1.data('result').on('data',function(properties){
            BuildInfo(search1.data('results').data().rows);
         }

    }
}

But the bad side is if the number search manager will keep growing if user keep run the page without page load.
For the second error. I have no idea to fix.

Tags (2)

bmacias84
Champion

Hello,

I had very similar issue. I was able to work around the issue by using epoch and attaching it to my id. For the second issue you can set the timeout attribute in the search manager. The timeout specifies in seconds how long to keep the search after processing has stopped.


poolSearch = new SearchManager({
                        id: elementSearch+epoch,
                        autostart: "true",
                        latest_time: "now",
                        earliest_time: "-1d@d",
                        cache: 'false',
                        search: splunkQuery,
                        timeout: "5"
                    });

0 Karma

sumangala
Path Finder

With timeout: "5" setting doesn't resolve the issue. Is there any other way?

0 Karma

chrismok
Path Finder

Anyone meet this case?

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Make Your Machine Data AI-Ready in Splunk

Every team is getting ready for AI agents.   Thursday, November 12, 2026  |  11AM  PST / 2PM EST   ...

Splunk Asynchronous Forwarding Explained

Splunk asynchronous forwarding is often misunderstood as simply setting autoLBVolume. That is not quite right. ...

How to Monitor AI Agents with Splunk Agent Observability

Let’s say I’m running a travel planning AI app in production. A user asks for three concise hotel options in ...