Splunk Dev

Java SearchManager condition execution of function

yogip86
Explorer

I am working with JavaSDK to execute custom python script.  In below code, i want to execute errorfunc (highlighted) in case "myResults.on("data", function ()" even is not triggered. How i can put non event condition. 

require([
'underscore',
'jquery',
'splunkjs/mvc',
"splunkjs/mvc/searchmanager",
'splunkjs/mvc/simplexml/ready!'
], function (_, $, mvc, SearchManager) {
console.log("sample.js has been loaded");
buttonClick()

function buttonClick(){
$("#run_search_btn").on("click",function(){
console.log("Clicked")
$('#run_search_btn').attr( "disabled", "disabled" );

script1 = "| script XPDM_Creation"

function success(val_cnt,val){
console.log("Search Result: Successful");
console.log("Result:",val_cnt);
console.log(val);
alert("Generated");
$("#run_search_btn").removeAttr( "disabled");
}
function err(){
console.log("Search Result: Failed");
alert("Generation Failed")
$("#run_search_btn").removeAttr( "disabled");
}

runScript1(script1,success,err)

})
}


function runScript1(script1, successfunc, errorfunc) {
var result = [];
var lookupSearch = new SearchManager({
earliest_time: "-24h@h",
latest_time: "now",
search: script1
});
var myResults = lookupSearch.data("results");

lookupSearch.on("search:done", function () {
console.log(myResults)
myResults.on("data", function () {
result_cnt = myResults.data().rows;
myResults_text = myResults.data().rows[0][0];
successfunc(result_cnt,myResults_text)
})
errorfunc()
});


lookupSearch.on('search:failed', function(properties) {
// Print the entire properties object
console.log("FAILED:", properties);
errorfunc()
});

lookupSearch.on('search:error', function(properties) {
// Print the entire properties object
console.log("FAILED:", properties);
errorfunc()
});

lookupSearch.on('search:progress', function(properties) {
// Print just the event count from the search job
console.log("IN PROGRESS.\nEvents so far:", properties.content.eventCount);

});


}
})

Labels (4)
0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...