Facing issue while closing Parent Incident

Waquar
Kilo Contributor

We are getting a pop up to first close all the child incidents by updating the CI details when we trying to close the parent incident. This is a very time taking manual process as we tag 10-15 child incidents to a parent incident.

 

Please advise how it can be fixed.

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@Waquar This can be addressed by creating an on After update business rule on the incident table with the following conditions.

 

Parent is Empty

AND

State changes to Closed

 

Here is the script.

 

 var grChild = new GlideRecord('incident');
    grChild.addQuery('parent', current.sys_id);
    grChild.query();

    while (grChild.next()) {
        grChild.state = 7; // Set state to Closed
        grChild.cmdb_ci = current.cmdb_ci; // Update the CI field
        grChild.update();
    }

 Hope this helps.

Anand Kumar P
Giga Patron
Giga Patron

Hi @Waquar ,

create after update business rule state changes and parent is empty.

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

  
    var childIncidents = new GlideRecord('incident');

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

    childIncidents.addActiveQuery();

    childIncidents.query();

    while (childIncidents.next()) {

        childIncidents.state = 7;

       childIncidents.cmdb_ci= current.cmdb_ci;

        childIncidents.update();

    }

})(current, previous);

 

 

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand

Runjay Patel
Giga Sage

Hi @Waquar ,

 

Check the before BR which is running to prevent closing the incident if child incident are open. You need to change the logic there as this functionality is not OOB. Instead of preventing you can close the child incident by using below script.

var grChild = new GlideRecord('incident');
    grChild.addQuery('parent', current.sys_id);
    grChild.query();

    while (grChild.next()) {
        grChild.state = current.state; // Set state to Closed
        grChild.update();
    }

 

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

PritamG
Mega Guru

To fix this, create a Business Rule or a Flow Designer automation to automatically update and close all child incidents when the parent incident is closed. This eliminates the need for manual updates.