Dashboards & Visualizations

Is a Javascript event called when a SearchManager search returns no data?

jmurdza
Explorer

If search is a SearchManager, the callback search.data("results").on("data", callback) is called when a search returns more than zero events. However I want to know when there are zero events returned.

I see search.on("search:done", callback) and search.on("change", callback) are also callbacks called when a search is finished, but they always called before search.data("results").data() is populated.

How can I consistently know when there is no data returned from a search?

1 Solution

dgladkikh_splun
Splunk Employee
Splunk Employee

search:done event is triggered with two arguments, first is the search manager state object, second is the js sdk job object. First argument can tell you number of events / results.


search.on("search:done", function(state, job) {
if (state.content.resultCount === 0) {
alert("no results");
}
});

View solution in original post

dgladkikh_splun
Splunk Employee
Splunk Employee

search:done event is triggered with two arguments, first is the search manager state object, second is the js sdk job object. First argument can tell you number of events / results.


search.on("search:done", function(state, job) {
if (state.content.resultCount === 0) {
alert("no results");
}
});

tommywang
Explorer

This really helps me a lot. I tried some stupid ways to deal with this situation. Is this written into the documentation? It should be.

0 Karma

jeffland
SplunkTrust
SplunkTrust

This should find its way into the documentation... or is it already in there, but I didn't find it?

0 Karma

kikexclusive
Path Finder

I have the exact same question about the documentation. Do we have to guess these workarounds?

0 Karma

yurykiselev
Path Finder

Splunk web framework documentation is terrible!

0 Karma
Get Updates on the Splunk Community!

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...