How to stop a scheduled job to run with conditional script

Joshua Comeau
Kilo Sage

Looking to write a scheduled job conditional script that would query on the assignment group and the short description of the sctask and if it returns true do not run else run the job 

 

Any ideas on what could be wrong with the following script:

var gr = new GlideRecord('task');
gr.addQuery('assignment_group', 'Home Office Building Operations');
gr.addQuery('short_description', 'Monthly Sprinkler System Maintenance - Home Office');
gr.addActiveQuery();
gr.query();

if (gr.next()) {
return true;
} 
else {
 return false;
}
1 ACCEPTED SOLUTION

Community Alums
Not applicable

@Joshua Comeau ,

this should work,

 

answer= true;
var gr = new GlideRecord('sc_task');
gr.addEncodedQuery('assignment_group=SYS_ID of Home Office Building Operations^short_descriptionLIKEMonthly Sprinkler System Maintenance - Home Office');
gr.addActiveQuery();
gr.query();
 
if (gr.next()) {
answer=false;
} 
else {
answer= true;
}

 

View solution in original post

6 REPLIES 6

Community Alums
Not applicable

@Joshua Comeau ,

this should work,

 

answer= true;
var gr = new GlideRecord('sc_task');
gr.addEncodedQuery('assignment_group=SYS_ID of Home Office Building Operations^short_descriptionLIKEMonthly Sprinkler System Maintenance - Home Office');
gr.addActiveQuery();
gr.query();
 
if (gr.next()) {
answer=false;
} 
else {
answer= true;
}

 

Community Alums
Not applicable

@Joshua Comeau ,

This scheduled job will not run if there are active SC_tasks assigned to home office and short description you mentioned.