Quantcast
Channel: Questions in topic: "splunk-enterprise"
Viewing all articles
Browse latest Browse all 47296

What is the proper way for listening SearchManager results in JavaScript

$
0
0
I tried the following ways: **Way 1**: One method is to run search and wait for its results is as follows: require([ "splunkjs/mvc/searchmanager", "splunkjs/mvc/simplexml/ready!" ], function ( SearchManager ) { // search to run var defaultTableSearch = new SearchManager({ id: "populate-default-table", preview: true, cache: true, search: mvc.tokenSafe(`##your search query here##`) }); // fetch results from search var defaultResults = defaultTableSearch.data("results"); // wait for the search to return results defaultResults.on("data", function () { var data = defaultResults.data(); // do something with data... }); }); **Problem with Way 1**: With the above method, if our search doesn't result in any data then it will not trigger `on("data" ...);` at all. **Way 2**: One other solution may be to listen onto `search:done` event on search manager **Problem with Way 2**: it's not guaranteed we will get results immediately after that event gets triggered. Is there something wrong I'm doing or something I'm missing? Note: Blocking search solves this but I want to find a proper way to do it asynchronously. Thanks.

Viewing all articles
Browse latest Browse all 47296

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>