Close child cases when parent is closed

Deepika28
Tera Contributor

In HR case, when parent case state is changed to closed complete, if any of the child cases are not closed, then error/info message has to show up saying child cases are not closed. 

This has to happen without scripting. Any suggestions on this? 

9 REPLIES 9

Similar to below query as per the relation field whatever field is there in HR module which holds sys_id of parent

var rec = new GlideRecord("incident");
rec.addQuery("parent_incident", current.sys_id);

Yes you can write custom BR but you have to make in-active the OOB BR

Deepika28
Tera Contributor

What are the other options apart from business rule i can use?

keithl22
ServiceNow Employee
ServiceNow Employee

Business Rule is really the way to go. You could try to do something with workflow editor or Flow designer as well, but it would still require some scripting and it would be more complex. You could also write a UI Action (make a button) that would close the case and all child tasks, however this would also require some scripting to accomplish. No way to do it that I am aware of that does not involve writing a script of some sort.  

Rob Sestito
Mega Sage

Hello- 

As everyone here is stating, Business Rule would be the way to go, to abort the closing of the parent case while the child case is still active.

For our system, we had a BR to abort the closing of a case when there was an hr task attached, that was still active.

So, I basically took that logic and applied it to a BR for Parent and Child cases. Here is what we have:

find_real_file.png

 

For the advanced tab:

Condition: current.state.changesTo(20)

Script:

(function executeRule(current, previous /*null when async*/) {
	var recObj = new GlideRecord('sn_hr_core_case');
	recObj.addQuery('parent', current.sys_id);
	recObj.addQuery('active', 'true');
	recObj.query();
	if (recObj.hasNext()) {
		gs.addErrorMessage('Unable to close Case due to an open Child Case. All related Child Cases must be closed before closing the Case.');
		current.setAbortAction(true);
	}
})(current, previous);

of course, you could make your message something different, but this is what we have. So, if I try to close a parent case with an active child case:

Active HR Child Case with Active Parent Case:

find_real_file.png

While on the Parent Case and clicking on the Close Complete UI Action (to move to awaiting acceptance state):

find_real_file.png

 

Give this a try and do some testing - let us know if this works or not for you!

Cheers,

-Rob