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!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...