have to create a business rule to close the RITM and REQ if the all related tasks got closed.

lakng
Tera Contributor

the issue here is , few requests are not getting closed.

so i want to create a busienss rule to check all the related tasks are got closed or not.

if all closed it has to close the RITM and REQ.

if not it should not execute.

please help me with the sample code.

it has to check manual tasks as well.

6 REPLIES 6

rajmasurkar
Giga Guru

Hi,

 

I might not have understood the requirement correctly.

But this is the OOB functionality available in Service Now.

 

Raj

no i did not found any OOB related to my issue.

here i wants to create a functionality to close the RITM based on the related catalog tasks to that RITM.

Hi,

I have posted sample script for the same in the below link; it is similar question asked by you

https://community.servicenow.com/community?id=community_question&sys_id=25ff58e3db68c0d014d6fb243996...

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Chavan AP
Tera Guru

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.

Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****