Auto-closure of all child incidents and it's tasks if parent incident is set to resolved.

Savvy
Tera Contributor

For now, the script has been written in way where if any incident is set to resolved where there is open tasks, or if the child incident has open tasks, info message will be shown so that first close the open tasks, and then only you can resolve.

But I want one more feature to be added in it. 
We want the auto-closure of all child incidents (incl. open incident tasks of the child incidents) if the PARENT Incident has been set to resolved. The open tasks of a parent incident needs to be closed manually. If someone tries to resolve the parent incident without having the incident_tasks closed before, they will get the Infomessage as a reminder "Unable to close the Incident request as there are open Incident tasks". The same behavior for all other incidents.

Following information should be set when an open task will be closed automatically:
State: Closed Skipped
Work Note in Task: Incident Task was automatically closed due to resolving of Parent Incident.

Please help me on how can I add this new feature into this current BR:

(function executeRule(current, previous /*null when async*/) {
	
var count = new GlideAggregate('incident_task');
count.addAggregate('COUNT');
count.addQuery("incident",current.sys_id);	
count.addActiveQuery();
count.query();
var incidents = 0;

	if(count.next()) 
	   incidents = count.getAggregate('COUNT');
	
	
	if ( incidents >0) {
		gs.addInfoMessage(gs.getMessage('Unable to close the Incident request as there are open Incident tasks'));
		current.state = previous.state;
		current.setWorkflow(false);
		current.setAbortAction(true);
	}
})(current, previous);

Thank You.

6 REPLIES 6

Jake Sadler
Kilo Sage

Hi,

 

Create a new an after update business rule that runs on the parent with conditions state = resolved.

 

var gr = new GlideRecord('incident');

gr.addQuery('parent',current.sys_id);

gr.query();

 

while(gr.next()){

 

gr.state = ?//add state number value

gr.work_notes = ' Incident Task was automatically closed due to resolving of Parent Incident';

gr.update();

 

Thanks

 

Jake

Hi, Thankyou for the response. 
But this is not working. This is updating the state and worknotes of child incidents, i want to update the state and worknotes of child incident's tasks.

Also,when resolving from parent, it is not resolving the child incident which has open tasks.

Savvy
Tera Contributor

Hi @Ankur Bawiskar 
Can you please help me in this?

@Savvy 

So you want child incident and child incident's task to be closed when parent incident is closed?

update as this

BR Condition: State Changes to Resolved

(function executeRule(current, previous /*null when async*/) {

	var gr = new GlideRecord("incident");
	gr.addActiveQuery();
	gr.addQuery("parent_incident", current.getUniqueValue()).addOrCondition("incident", current.getUniqueValue);
	gr.query();
	while(gr.next()) {

		// check for open incident tasks
		var rec = new GlideRecord('incident_task');
		rec.addActiveQuery();
		rec.addQuery('parent', gr.getUniqueValue()).addOrCondition('incident', gr.getUniqueValue());
		rec.query();
		while(rec.next()){
			rec.state = '3'; // give correct choice value
			rec.close_notes = 'Closing as incident is getting auto closed';
			rec.update();
		}

		gr.state = '7'; // give choice value
		gr.close_code = 'Solved (Work Around)';
		gr.close_notes = 'Auto closed';
		gr.update();
	}

})(current, previous);

Regards
Ankur

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