RITM not closing when SC_task is closed

Leslie Hornyak
Tera Contributor

I have a workflow that is generating multiple RITMS and SC_tasks from a list collector.

Many thanks to @Brad Bowman  for helping me get this completed using a workflow script.  A RITM is created with the master collection of apps requested and a separate RITM for each individual APP along with a corresponding SC_Task for that APP assignment group.

 

The issue now is that when i close any of the individual SC_Tasks, the associated RITM is not getting updated to a closed complete State.

 

Ive tried to add a BR where it checks the status of the SCTask record for closed complete , incomplete or skipped and then force the workflow .... 

 

var ritmRec = new GlideRecord('sc_req_item');

if(ritmRec.get(current.request_item)) {

new Workflow().broadcastEventToCurrentsContexts(ritmRec, 'update', null);

}

})(current, previous);

 

Ive also tried to set a wait for condition in the workflow but neither seem to be working correctly.

TIA

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

You probably only have one workflow running - on the original RITM, not on each one created by the script - which sounds like it's probably OK in this simple case, but since the tasks are created by script, even if there were a workflow running on each RITM, it still wouldn't catch a task closing. 

You'll want your after Update Business Rule on sc_task to have Filter Conditions for the State changing to one of the closed ones (or you can use Active changes to false) and when Request Item -> Item (show related fields) is this Catalog Item, so that it doesn't run on every task closure.  Your script would look like this to set the State of the RITM

var ritmRec = new GlideRecord('sc_req_item');
if(ritmRec.get(current.request_item)) {
//if you want the RITM to be Closed Incomplete when the Task is Closed Incomplete, etc
ritmRec.state = current.state;
//or if you want the RITM to always be Closed Complete, use the next line instead
//ritmRec.state = 3;
ritmRec.update();  

If this gets more complex you could add variable population and workflow starting to your original script and remove the task creation.  Then make sure the same script accounts for it running against the original RITM, and for each created one, so that it doesn't create RITMs again every time it runs.  Doing this would allow you to add catalog task(s), and whatever else you need to do before each workflow and RITM is closed, and you wouldn't need business rules to intervene.  I have a couple of catalog items running like this if you need an example.

View solution in original post

7 REPLIES 7

Brad Bowman
Kilo Patron
Kilo Patron

You probably only have one workflow running - on the original RITM, not on each one created by the script - which sounds like it's probably OK in this simple case, but since the tasks are created by script, even if there were a workflow running on each RITM, it still wouldn't catch a task closing. 

You'll want your after Update Business Rule on sc_task to have Filter Conditions for the State changing to one of the closed ones (or you can use Active changes to false) and when Request Item -> Item (show related fields) is this Catalog Item, so that it doesn't run on every task closure.  Your script would look like this to set the State of the RITM

var ritmRec = new GlideRecord('sc_req_item');
if(ritmRec.get(current.request_item)) {
//if you want the RITM to be Closed Incomplete when the Task is Closed Incomplete, etc
ritmRec.state = current.state;
//or if you want the RITM to always be Closed Complete, use the next line instead
//ritmRec.state = 3;
ritmRec.update();  

If this gets more complex you could add variable population and workflow starting to your original script and remove the task creation.  Then make sure the same script accounts for it running against the original RITM, and for each created one, so that it doesn't create RITMs again every time it runs.  Doing this would allow you to add catalog task(s), and whatever else you need to do before each workflow and RITM is closed, and you wouldn't need business rules to intervene.  I have a couple of catalog items running like this if you need an example.

Thansk @Brad Bowman . It took a bit of time to figure out why the BR was not working but then i set the order to 999 and Update and that did the trick. Many thanks for the help.

 

You are welcome!