Cannot query v_cluster_transaction from Scheduled Job

Marcin Witoslaw
Tera Contributor

Hello All ,

I try to abort execution of Scheduled Job when other scheduled Jobs (from a list ) are running. Script works in Background but there  is no query to v_cluster_transaction table in Scheduled Job

 

my script :

var scheduledJobs = [
    "Matching Process",
    "Identification Process",
    "Notification Process",
    "event.process.notification",
    "event.process.matching",
];
var result = false;

for (var i = 0; i < scheduledJobs.length; i++) {
    var jobName = scheduledJobs[i];
    var clusterGr = new GlideRecord("v_cluster_transaction");
    clusterGr.addQuery('url', 'CONTAINS', jobName);
    clusterGr.query();
    if (clusterGr.hasNext()) {
        result = true;
        break;
    }

}
I have put it into a Script Include 'ProcessUtils' under  abortScheduledJobExecution(currentJobName) method and called from Scheduled Jobs : 
"Matching Process",
    "Identification Process",
    "Notification Process",
Here is an example code from Identification Process Scheduled Job :
(function() {
var currentJobName = "Identification Process";
var util = new global.ProcessUtils();
if (util.abortScheduledJobExecution(currentJobName)) {
    gs.log("Abort execution'" + currentJobName + "' due to another running job.");
    return;
}
})();
 
Cannot query v_cluster-transaction table. I have changed my query table for incident and everything was fine.
Please Help.
 
1 ACCEPTED SOLUTION

Nilesh Pol
Tera Guru

@Marcin Witoslaw verify a link: Solved: Script to get active transactions from all nodes t... - ServiceNow Community 

it specifies and query v_cluster_transaction from Scheduled Job

 

if this response helps you, then mark helpful and accept as a solution.

View solution in original post

7 REPLIES 7

Marcin Witoslaw
Tera Contributor

Still the same unfortunatelly.

@Marcin Witoslaw 

Use this revised script:

var result = false;

for (var i = 0; i < scheduledJobs.length; i++) {
var jobName = scheduledJobs[i];
if (!jobName || jobName === currentJobName) {
result = true;
continue;
}
var clusterGr = new GlideRecord("v_cluster_transaction");
clusterGr.addQuery('url', 'CONTAINS', jobName);
clusterGr.query();
if (clusterGr.hasNext()) {
result = true;
break;
}
}

return result;

 

Make sure these variables are properly initialized before this script runs.

Thank you @Nilesh Pol for a quick response but no luck still the same.