My REQ items aren't closing when all the RITM's and SCTASKS are done - where is this actually done?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 01:44 PM
My REQ items aren't closing when all the RITM's and SCTASKS are done - where is this actually done?
explained: I have many items that generate multiple SCTASKS and many REQ's the generate multiple RITM's. How do I monitor at the REQ level using business rules or flows or some other method to make sure that when the SCTASKS are all done on an RITM that it closes and then when all the RITM's on a REQ are closed that it closes?
If there's articles or other links out there please help me find them. I seem to drawing up blank when it comes to figuring out why this isn't happening and our REQ's are staying open.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 02:01 PM
Hi @Jeffrey Barton ,
While generally the closure of Requests (REQ) at the flow or workflow level for better control and consistency, if a more generic approach is desired, you can consider creating a Business Rule. The following example outlines a Business Rule to automatically close a REQ when all associated Requested Items (RITMs) are closed or canceled.
// Business Rule Name: CloseREQWhenRITMDeactivated
// Table: sc_req_item (Requested Item)
// When to run: After Update
//condition active changes to false
(function executeRule(current, previous ) {
// Query all RITMs related to the same REQ
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery('request', current.request);
ritmGr.query();
var allRITMsClosed = true;
// Check if all related RITMs are closed or canceled
while (ritmGr.next()) {
if (ritmGr.state != 'closed' && ritmGr.state != 'canceled' && ritmGr.sys_id != current.sys_id) {
allRITMsClosed = false;
break;
}
}
// If all other RITMs are closed or canceled, close the REQ
if (allRITMsClosed) {
var reqGr = new GlideRecord('sc_request');
if (reqGr.get(current.request)) {
reqGr.state = 'closed';
reqGr.update();
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 02:16 PM - edited 02-21-2024 02:17 PM
Hi @Jeffrey Barton ,
You need to add into the workflow you are using for the item a stage of complete when the SCTASK is completed:
Just add a Stage, Hovering under the task you can select from the available options
Hope that help you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 03:12 PM
That was the perfect place to start the troubleshooting. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 03:29 PM
Hey @Jeffrey Barton, notice the conditions that the "Close Parent if Required" business rule is triggered on - they all relate to the "stage" associated to the RITM:
Make sure the "stage' is being set on your catalog item flows so when they complete the flow sets the RITM stage to complete. This business rule will also trigger when the stage moves to cancelled, closed incomplete or closed skipped.
Hope this helps, Brent