- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 03:47 AM
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;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 04:30 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 03:56 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 04:02 AM - edited 08-13-2024 04:10 AM
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;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 04:13 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 04:15 AM
Does it require the function though?