Auto close when parent incident is closed automaticcally child incident to be closed and also same
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 05:49 AM
Hi,
When parent incident is closed then automatically child incident will be closed and When child incident closed then automatically parent incident will be closed (Both sides).
How to achieve this and I tried this code but not working for me so can you please give me a code.
Thanks in Advance!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 06:06 AM
What part of the code is not working for you?
Childs should be closed with this.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 06:11 AM - edited 08-29-2023 06:15 AM
I need for both of these business rule code When parent incident is closed then automatically child incident will be closed and When child incident closed then automatically parent incident will be closed (Both sides).- both codes are not working can you please provide me working codes.
Thanks
Maniseshu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 06:18 AM
Hi @mania,
var parent = new GlideRecord('incident');
if (parent.get(current.parent)){
if (parent.active){
parent.state = 7;
parent.update();
}
}
else{
var childs = new GlideRecord('incident');
childs.addQuery('parent',current.sys_id);
childs.addQuery('state', '!=', 7);
childs.query();
childs.state = 7;
childs.updateMultiple();
}
Try this, and remove the parent incident is empty from your condition.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 06:21 AM
Hi @mania
Try this, I tested this and it is working in my PDI.
(function executeRule(current, previous /*null when async*/ ) {
//Close all childs
var gr = new GlideRecord("incident");
gr.addQuery("parent_incident", current.getUniqueValue());
gr.addQuery("state", "!=", "7");
gr.query();
while (gr.next()) {
gr.setValue("state", "7");
gr.setValue("close_code", current.getValue("close_code"));
gr.setValue("close_notes", current.getValue("close_notes"));
gr.update();
}
//Close parent
var grP = new GlideRecord("incident");
if (grP.get("sys_id", current.getValue("parent_incident"))) {
grP.setValue("state", "7");
grP.setValue("close_code", current.getValue("close_code"));
grP.setValue("close_notes", current.getValue("close_notes"));
grP.update();
}
})(current, previous);
Anvesh