Close RITM once all tasks have been closed

jacobpeterson
Mega Expert

Hello all,

I have a RUN SCRIPT that creates multiple tasks based on a list collector but after it creates the tasks the workflow continues and closes the RITM. I need the RITM to stay open until all of the SCTASK have been closed.

I have tried using this script with a 'Wait for Condition' and while it does stop the RITM from closing, once all the SCTASK have been closed the RITM stay's open.

//Query for all tasks to see if they are inactive
var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.sys_id);
rec.addQuery('active', true);
rec.query();
if(rec.hasNext()){
answer = false;
}
else{
//Continue
answer = true;
}

Thank you for any help!

1 ACCEPTED SOLUTION

awessel
Kilo Guru

This is likely caused by the fact that the catalog tasks' closure is not triggering the workflow to continue running. What you'll need to do is create a business rule on the catalog task that triggers the RITM's workflow when the task is closed. That script will look something like this:



var ritmRec = new GlideRecord('sc_req_item');


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


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


}




PS - this BR on the catalog task table should be an after BR as it is interacting with another table.


View solution in original post

6 REPLIES 6

Jaspal Singh
Mega Patron
Mega Patron

Hi Jacob,



Could you try using rec.next() instead of rec.hasNext().


Jaspal,



Thanks but it did not work.