I want to close all child incidents after closing parent incident?

JMR2
Mega Expert

Hi all,

I want to close all child incidents after  closing parent incident, if any one child incident not closed the parent incident should not be close? 

updateChildIncidents();
function updateChildIncidents() {
var msg = "";
var commentsMsg="";
var grIncident = new GlideRecord("incident");
grIncident.addActiveQuery();
grIncident.addQuery("parent_incident", current.sys_id);
grIncident.query();
while(grIncident.next()){
if(current.state.changesTo("6")){
gs.addInfoMessage('incident state'+grIncident.state);
if(grIncident.state=="8") // If the child incident in state awaiting for parent, we resolve it.
grIncident.state = "6";
commentsMsg = "Resolved based on resolution of Parent Incident.";
}
if(current.state.changesFrom("6") && !current.state.changesTo("7")){ // If the parent incident is reopened we update the state of child if was resolved by the parent
if(grIncident.state=="6" && grIncident.close_notes.toString().indexOf("Solution copied from Parent Incident")!=-1) {
grIncident.state = "8";

if(!current.work_notes){
grIncident.work_notes = "Parent Incident reopened";
}
}
}
if(current.close_notes.changes()){
msg = "Solution copied from Parent Incident";
if (current.close_notes.toString().indexOf(msg) == 0)
grIncident.close_notes = current.close_notes;
else
grIncident.close_notes = msg + ": " + current.close_notes;
}
if(current.close_code.changes()){
grIncident.close_code = current.close_code;
}
copyCommentsAndWorkNotesFromParent(grIncident,commentsMsg,null);
grIncident.update();
}
}
function copyCommentsAndWorkNotesFromParent(incident,commentsMsg, notesMsg){
if(current.comments) {
if(!commentsMsg)
commentsMsg = "Comment copied from Parent Incident";
if (current.comments.toString().indexOf(commentsMsg) == 0)
incident.comments = current.comments;
else
incident.comments = commentsMsg + ": " + current.comments;
}
if(current.work_notes) {
if(!notesMsg)
notesMsg = "Work note copied from Parent Incident";
if (current.work_notes.toString().indexOf(notesMsg) == 0)
incident.work_notes = current.work_notes;
else
incident.work_notes = notesMsg + ": " + current.work_notes;
}
}

7 REPLIES 7

What is the error? I Have tested in my instance and its working. Make Business rule order 500.
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

 

Thank you,
Abhishek Gardade

why var closedChild = 0 you're not using it in your code

and its not working 

Devyani_6
Mega Guru

Hi,

Follow below thread, this may resolve your query.

I want to close all child incidents before closing parent incident, if any one child incident not cl...

Regards,

Devyani

www.dxsherpa.com

Hit Correct/Helpful, based on the impact of the response.