updateChildIncidents(); function updateChildIncidents() { if (current.state.changesTo(IncidentState.RESOLVED)) { resolveChildIncidents(); } else if (current.state.changesTo(IncidentState.CLOSED)) { closeChildIncidents(); } else { var fields = []; var value; if (current.comments.changes()) { value = deriveFieldValue('comments', gs.getMessage('Comment copied from Parent Incident')); if (value && value != "") fields.push({name: 'comments', value: value}); } if (current.work_notes.changes()) { value = deriveFieldValue('work_notes', gs.getMessage('Work note copied from Parent Incident')); if (value && value != "") fields.push({name: 'work_notes', value: value}); } updateChildren(fields); } } function deriveFieldValue(fieldName, msg) { var fieldRawValue = current.getValue(fieldName) + ''; var fieldValue = fieldRawValue.trim(); if (fieldValue && fieldValue.length > 0) { if (fieldRawValue.indexOf(msg) == 0) return (fieldRawValue); else return (msg + ": " + fieldRawValue); } return; } function updateChildren(fields) { if (fields.length < 1) return; var rec = new GlideRecord("incident"); rec.addQuery("parent_incident", current.sys_id); rec.addQuery("state", "!=", IncidentState.RESOLVED); rec.addActiveQuery(); rec.query(); while (rec.next()) { for (var i = 0; i < fields.length; i++) { rec[fields[i].name] = fields[i].value; } rec.update(); } } // // Resolve active, unresolved incidents that are children of the current incident // function resolveChildIncidents() { //check if update is valid or aborted before updating child incidents if(current.isActionAborted()) return; var incident = new GlideRecord("incident"); incident.addActiveQuery(); incident.addQuery("parent_incident", current.sys_id); incident.addQuery("state", "!=", IncidentState.RESOLVED); incident.query(); var msg = ""; while (incident.next()) { gs.print("Incident " + incident.number + ' resolved based on resolution of Parent Incident ' + current.number); incident.state = IncidentState.RESOLVED; if (incident.close_notes.nil()) { msg = gs.getMessage('{0} copied from Parent Incident', current.close_notes.getLabel()); if (current.close_notes.toString().indexOf(msg) == 0) incident.close_notes = current.close_notes; else incident.close_notes = msg + ": " + current.close_notes; } if(incident.isValidField("close_code")) incident.close_code = current.close_code; msg = gs.getMessage("Resolved based on resolution of Parent Incident."); if (current.comments.toString().indexOf(msg) == 0) incident.comments = current.comments; else incident.comments = msg + " " + current.comments; incident.work_notes = current.work_notes; //add new code here to set assignment group and assigned to incident.assignment_group = current.assignment_group; incident.assigned_to = current.assigned_to; incident.update(); } } function closeChildIncidents() { //check if update is valid or aborted before updating child incidents if(current.isActionAborted()) return; var incident = new GlideRecord("incident"); incident.addActiveQuery(); incident.addQuery("parent_incident", current.sys_id); incident.addQuery("state", "!=", IncidentState.CLOSED); incident.query(); var msg = ""; while (incident.next()) { gs.print("Incident " + incident.number + ' closed based on resolution of Parent Incident ' + current.number); incident.state = IncidentState.CLOSED; if (incident.close_notes.nil()) { msg = gs.getMessage('{0} copied from Parent Incident', current.close_notes.getLabel()); if (current.close_notes.toString().indexOf(msg) == 0) incident.close_notes = current.close_notes; else incident.close_notes = msg + ": " + current.close_notes; } if(incident.isValidField("close_code")) incident.close_code = current.close_code; msg = gs.getMessage("Closed based on resolution of Parent Incident."); if (current.comments.toString().indexOf(msg) == 0) incident.comments = current.comments; else incident.comments = msg + " " + current.comments + " : " + current.number; incident.work_notes = current.work_notes; //add new code here to set assignment group and assigned to incident.assignment_group = current.assignment_group; incident.assigned_to = current.assigned_to; incident.update(); } }