Prevent Closure of a Parent Incident if It Has Open Child Incidents

arshadansar
Tera Contributor

Don't Know why its not working. 

current.setAbortAction(true); 
 
arshadansar_0-1748089473694.pngarshadansar_2-1748089524575.png

 

arshadansar_1-1748089509632.png

 

Want not closed incident if child incident is open.

1 ACCEPTED SOLUTION

Hello @arshadansar ,

 

Ok, got it, thanks. Please update your Business Rule script as follows:

 

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

    var childTask = new GlideRecord('incident');
    childTask.addQuery('parent_incident', current.getUniqueValue());
    childTask.addQuery('state', '!=', '7'); // not closed
    childTask.query();

    var arr = [];
    while (childTask.next()) {
        arr.push(childTask.getValue('number'));
    }

    if (arr.length > 0) {
        gs.addErrorMessage('Cannot update the parent Incident until all child Incidents are closed: ' + arr.join(', '));
        current.state = previous.state;
        current.incident_state = previous.incident_state;
        current.setAbortAction(true);
    }

})(current, previous);

 

And make sure the BR "When" field is set to "before", not "after".

 

Regards,

Robert

View solution in original post

6 REPLIES 6

Thanks @Robert H. It's Working Now... 🙂

Harish Bainsla
Kilo Patron
Kilo Patron

Hi @arshadansar check below link

https://www.servicenow.com/community/itsm-forum/how-to-close-parent-incident-if-all-child-incidents-...

if my answer helps you mark helpful and accept solution