Need a script for when parent incident closes, related child incidents shold close automatically.

hrbhavana
Kilo Contributor

Need a script for when parent incident closes, related child incidents shold close automatically.

Please explain with example

3 REPLIES 3

Harsh Vardhan
Giga Patron

try with below script. 

 

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

	// Add your code here
	// Query for associated records related to the same parent
	var inc = new GlideRecord('incident');
	inc.addQuery('parent_incident', current.sys_id); 	
	inc.addActiveQuery();
	inc.query();
	while(inc.next()) {
			
		inc.state = 7; // Close the incident
		inc.active = false;
		inc.update();
	}

})(current, previous);

Harsh Vardhan
Giga Patron

also want to add here, there is already ootb business rule which does this. 

Business Rule Name : Update Child Incidents

 

try to have a look that business rule. 

johnfeist
Mega Sage
Mega Sage

Hi,

You want to do something like this in an after update business rule:

var children = new GlideRecord("incident");
children.addQuery("parent", current.sys_id);
children.query();
while (children.next()) {
   children.state = 7;
   children.close_code = current.close_code;
   children.close_notes = current.close_notes;
   children.update();
}

This will not only close the children, it will also give them the notes and code from the parent.  This will apply to all child incidents even if some may already be closed if you want to avoid that you can add:

children.addQuery("state", "<", 6);

before the query.  This will look for anything that hasn't been resolved, closed or cancelled.  To include resolved incidents change the 6 to a 7.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

 

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster