My REQ items aren't closing when all the RITM's and SCTASKS are done - where is this actually done?

Jeffrey Barton
Tera Contributor

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.

4 REPLIES 4

Srinivasa1
Tera Expert

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);



Marco0o1
Tera Sage

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:

 

Marco0o1_0-1708553753284.png

Just add a Stage, Hovering under the task you can select from the available options

Marco0o1_1-1708553775223.png

Marco0o1_2-1708553829969.png

 

Hope that help you

That was the perfect place to start the troubleshooting.  Thank you.

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:

BrentSutton_0-1708557952477.png

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