Archive2

SearchManager, how to get results?

Explorer

Hi,
I wanna get results from search using for it this example in JS:
var SearchManager = require("splunkjs/mvc/searchmanager");
var GetResults = new SearchManager({
id: "getname",
earliest_time: "0",
latest_time: "",
preview: true,
cache: false,
search: "index=index_name | fields name"
});
var Result = GetResults.data("results", {output_mode: "json_rows", count: 0});
Result.on("data", function () {
resultArray = Result.data().rows;
$.each(resultArray, function (index, value) {
//Action with results
});
});

But when I add this at the bottom of the code, it does not work, although the results do not exist:
Result.on("search:done", function(state, job) {
if(state.content.resultCount === 0) {
alert("no results");
}
});

0 Karma
Reply