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

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.

Hello @Nilesh Pol ,

does it works for Schedule Job on demand ? ( when Execute Now  UI Action is clicked) ?

Marcin Witoslaw
Tera Contributor

I have added the following script to the scheduled Job :

function refreshTransactions() {
    var vct = new VClusterTransaction('v_cluster_transaction');
    vct.deleteTransactions();
    var id = vct.informOtherNodes();
    vct.refreshTransactions(gs.getSessionID());
    gs.sleep(35000);
}
and triggered it refreshtransactions();.Its works but now it aborting to trigger every schedule job mentioned in an array.
I have added the followind statement 
if (!jobName[i] || jobName === currentJobName) {
                result = true;
                continue;
            }
 
 
Now Script include part looks like this :
 
var result = false;

        for (var i = 0; i < scheduledJobs.length; i++) {
            var jobName = scheduledJobs[i];
            if (!jobName[i] || 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;

Nilesh Pol
Tera Guru

@Marcin Witoslaw As per the understanding, Script include checks whether a particulate scheduled job is run.

update your if condition is script include.

 if(jobname == currentJobName){

result = true;

continue;

}

 

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