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

HI @Joshua Comeau ,

is it task table or sc_task?

 

and also try adding encoded query, we should use sys_id's for reference fields and use IN, LIKE etc.., for string fields

This would be the sc_task table and can you provide the encoded query or full script you are hinting with

I assume you mean this; @Community Alums 

function checkTask() {
    var gr = new GlideRecord('sc_task');
    gr.addQuery('assignment_group', '=', 'Home Office Building Operations');
    gr.addQuery('short_description', 'CONTAINS', 'Monthly Sprinkler System Maintenance - Home Office');
    gr.addActiveQuery();
    gr.query();
    
    if (gr.next()) {
        return false;
    } else {
        return true;
    }
}

 

 

Community Alums
Not applicable

@Joshua Comeau ,

try this by passing sys_id of group.

 

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()) {
return false;
} 
else {
return true;
}

 

 

Does it require the function though?