Parent Incident to Close Child Incident

shadoworg
Giga Expert

Hello Community,

 

I want to close the child incidents when i close parent incidents using Script?

 

 

1 ACCEPTED SOLUTION

Samaksh Wani
Giga Sage
Giga Sage

Hello @shadoworg 

 

You need to Write Before Update BR Rule :-

 

 

if(current.state==closed complete){

var gr = new GlideRecord(‘incident’);
gr.addQuery(’parent’, current.sys_id);
gr.query();

while(gr.next()){

gr.state=‘closed complete’
gr.update();

}

 

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

 

 

View solution in original post

2 REPLIES 2

Samaksh Wani
Giga Sage
Giga Sage

Hello @shadoworg 

 

You need to Write Before Update BR Rule :-

 

 

if(current.state==closed complete){

var gr = new GlideRecord(‘incident’);
gr.addQuery(’parent’, current.sys_id);
gr.query();

while(gr.next()){

gr.state=‘closed complete’
gr.update();

}

 

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

 

 

Danish Bhairag2
Tera Sage
Tera Sage

Hi @shadoworg ,

 

You can create a after update BR n add below script

 

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

    // Check if the current record is an Incident and has been closed

    if (current.incident_state == '7') { // Assuming '7' is the closed state for incidents
        // Query child incidents
        var childIncident = new GlideRecord('incident');
        childIncident.addQuery('parent', current.sys_id);
        childIncident.query();
        // Loop through child incidents and close them
        while (childIncident.next()) {
            childIncident.incident_state = '7'; // Set to the closed state
            childIncident.update();
        }
    }

})(current, previous);

 

Please use proper backend values wherever required.

 

Thanks,

Danish