Join us Dec. 16 for The Community Hour, our first global virtual User Group event!

Close parent incident when the child incidents is closed

Shruthi8
Tera Contributor

Hi, 

I have a requirement that a Parent incident should get closed automatically if all the associated child incidents are closed.

A solution will be helpful.

Thanks in advance

4 REPLIES 4

Musab Rasheed
Kilo Patron

Hi Shruthi,

Try this with after business rule.

condition:current.active.changesTo(false) && current.parent.sys_class_name == 'incident'

 

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

// Query for associated records related to the same parent
var inc = new GlideRecord('incident');
inc.addQuery('parent', current.parent); // Records related to same parent
inc.addQuery('sys_id','!=', current.sys_id); // Exclude this record
inc.addActiveQuery();
inc.query();
c=inc.getrowcount();
gs.addInfoMessage("entered query");
if (!inc.next()) {
// If there are no other active records associated to the same parent
// Close the parent
gs.addInfoMessage("entered next look");
var parInc = new GlideRecord('incident');
parInc.get(current.getValue('parent'));
parInc.state = 7; // Close the incident
parInc.active = false;
parInc.update();
}

})(current, previous);

 

Use parent_incident instead of parent in case latter doesn't work.

 

Mark my answer as correct or hit like based on impact

Not applicable

hi i have a requirement same kind of.

user can select multiple groups on my parent table and it creates diferrent task for each group selected. but i want to autoclose the parent record if all the task of the groups is closed

 

Hello, where have you used this parameter?      c=inc.getrowcount(); Can you also check the code again and paste here?

Hello, the code works till 'gs.addInfoMessage("entered query");' . However it seem that you need to include 

close_code and close_notes too for the parent record to close. I have been trying. id not get any result.
ex:
 
 gs.addInfoMessage("entered next look");
        var parInc = new GlideRecord('incident');
        parInc.get('parent_incident', current.sys_id);
        parInc.state = 7;                                          // Close the incident
        parInc.close_code = 'User error';
        parInc.close_notes = 'tsttss';
        parInc.active = false;
         parInc.update();