How do I Close RITM , once tasks are closed (RITM and tasks are created through script in Runscript activity).

Chinmayee1
Giga Contributor

After first RITM and its task is closed , I am creating another additional RITM with 5 tasks in a Runscript activity.Everything is fine but when I close all the tasks, it doesnt close the RITM . Which is working fine for the first RITM automatically  but its not doing the same for the tasks and its RITM which are created through script.Can anyone advise on how do I trigger RITM to close once all the tasks are closed??

5 REPLIES 5

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Out of the box there is a business rule that runs on the task table called SNC - Run parent workflows IF:

task state changes to 3 (Closed Complete) or task state changes to 4 (Closed Incomplete) or task state changes to 7 (Cancelled)

 

If it meets these conditions then it will query for workflows running on the parent task and broadcast an "update" workflow event.  I mention this because you can leverage this in your workflow:

  • After your run script that creates the 5 tasks, use an If activity to check for open child tasks
  • If open tasks then use a Wait for WF event to wait for "update" and then go back to your If activity checking for open tasks
  • This will continue to loop until all tasks are closed
  • Once the tasks are closed, go to a set values of closed and done

Here is an example I used for testing purposes where I generate one task and then manually created other child tasks.  Again in your situation you would be replacing the Child Task (Catalog Task) activity with your run script that creates the 5 tasks.

find_real_file.png

 

Here is the script in the If activity:

answer = ifScript();

function ifScript() {
	var childTask = new GlideRecord("task");
	childTask.addActiveQuery();
	childTask.addQuery("parent", current.sys_id);
	childTask.query();
	if (childTask.hasNext()) {
		return 'yes';
	} else {
		return 'no';
	}	
}

Here is what the Wait for EF Event activity is set to:

find_real_file.png

Please mark this post as helpful of the correct answer to your question if applicable so others viewing can benefit.