workflow for ritm> need to create workflow activity on if sctask is closed skipped
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 02:24 PM - edited 02-27-2025 02:29 PM
So, I have a workflow for a request item that creates catalog tasks. I would like to have the "IF" workflow activity to check if the sctask before it was closed skipped and if so follow the alternate path. I have tried it and it doesnt seem to skip and follow the alternate path
// Check if the SCTASK in this RITM is "Closed Skipped"
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', current.sys_id);
taskGR.addQuery('state', 4); // State 4 = Closed Skipped
taskGR.query();
if (taskGR.next()) {
answer = true;
} else {
answer = false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 11:14 PM
share your current script inside IF activity.
Did you check my below response?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 11:51 PM
// This script needs to set answer to 'yes' or 'no' to indicate the state of the activity.
//
// For example,
//
// answer = ifScript();
//
// function ifScript() {
// if (condition is true) {
// return 'yes';
// }
// return 'no';
// }
// Check if the SCTASK in this RITM is "Closed Skipped"
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', current.sys_id);
taskGR.addQuery('state', 4); // State 4 = Closed Skipped
taskGR.query();
if (taskGR.next()) {
return 'yes';
} else {
return 'no';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2025 02:47 AM
Please update your script as below.
// Check if the SCTASK in this RITM is "Closed Skipped"
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', current.sys_id);
taskGR.addQuery('state', 4); // State 4 = Closed Skipped
taskGR.query();
if (taskGR.next()) {
answer = ‘yes’;
} else {
answer = ‘no’;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 03:41 PM
Hi @RBlor,
The script basically checks for any SCTAKS within the RITM which is "Closed Skipped". So if there is a SCTASK which is in other state (The screenshot does not show all workflow to see if there are other SCTASK created within the workflow), it will be queried and your script would return false. What you need to do is to:
- Add another query based on other fields which is unique on that specific SCTASK to make sure the query gets the right one checked. (Short description for example).
- Please use "yes" and "no" as returned values.
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 07:07 PM
try this
answer = ifScript();
function ifScript() {
// Check if the SCTASK in this RITM is "Closed Skipped"
var taskGR = new GlideRecord('sc_task');
taskGR.orderByDesc('sys_created_on'); // this checks the latest task
taskGR.addQuery('request_item', current.sys_id);
taskGR.addQuery('state', 4); // State 4 = Closed Skipped
taskGR.query();
if (taskGR.hasNext()) {
return 'yes';
} else {
return 'no';
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader