I'm new to Splunk, also not sure if this applies to you, so take this with a grain of salt. I have a dashboard where if the user presses a button then a search will be run and I will grab the results with the same method you used above. I was able to get this to run correctly the first time I pressed the button, however every subsequent time I got ,"Cannot read property 'rows' of undefined", and sometimes the results would be correct and sometimes they wouldn't.
I started logging search1Results outside and inside of the on('data') event handler and found that my issue had to do with the fact that I was creating more than one event handler, hence the reason I got it to work the first time and not subsequent. I still wanted to keep the event listener inside the button click listener so my fix was to just remove the on('data') event handler when I was finished with it.
My code was something like this before. Notice that each time I clicked the button I applied a new event handler:
mybutton.on('click', function () {
//stuff
var search1Results = search1.data("results");
search1Results.on("data", function() {
var search1Data = search1Results.data().rows;
});
});
This is my functioning code at the moment:
mybutton.on('click', function () {
//stuff
var search1Results = search1.data("results");
search1Results.on("data", function() {
var search1Data = search1Results.data().rows;
search1Results.off('data'); //Remove the event handler
});
});
Not sure if this applies to you or not. But hope it helps. I'm sure it can be done nicer. 🙂
... View more