- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2018 11:47 PM
Hi All,
Requirement is to update the child incidents whenever there is any update in parent incident's work notes or state.
I am struggling with my code, it only updates the state but in case of work notes change, it is not working.
Kindly help finding the issue. Below is the code-
BR- After
condition- current.isValidRecord()
code-
updateChildIncidents();
function updateChildIncidents() {
if (current.state.changesTo(6))
resolveChildIncidents();
else
updateChildren();
}
function updateChildren() {
var incState = current.state;
var fieldName= 'work_notes';
if(current.state.changes())
{
var chInc1 = new GlideRecord("incident");
chInc1.addQuery('parent',current.sys_id);
chInc1.addActiveQuery();
chInc1.addQuery('state','!=', '6');
chInc1.query();
while(chInc1.next()) {
chInc1.state = incState;
chInc1.update();
}
}
if(current.work_notes.changes()) {
msg = gs.getMessage('Work note copied from Parent Incident');
var rec2 = new GlideRecord("incident");
rec2.addQuery("parent", current.sys_id);
rec2.addQuery("state", "!=", "6");
rec2.addActiveQuery();
rec2.query();
while (rec2.next()) {
var fieldRawValue2 = current.getValue(fieldName) + '';
var fieldValue2 = fieldRawValue2.trim();
if (!fieldValue2 || fieldValue2.length <= 0)
return;
if (fieldRawValue2.indexOf(msg) == 0)
rec2[fieldName] = fieldRawValue2;
else
rec2[fieldName] = msg + ": " + fieldRawValue2;
rec2.update();
}
}
}
//
// Resolve active, unresolved incidents that are children of the current incident
//
function resolveChildIncidents() {
var incident = new GlideRecord("incident");
incident.addActiveQuery();
incident.addQuery("parent", current.sys_id);
incident.addQuery("incident_state", "!=", "6");
incident.query();
var msg = "";
while (incident.next()) {
gs.print("Incident " + incident.number + ' resolved based on resolution of Parent Incident ' + current.number);
incident.incident_state = 6;
if (incident.close_notes.nil()) {
msg = "Close notes copied from Parent Incident";
if (current.close_notes.toString().indexOf(msg) == 0)
incident.close_notes = current.close_notes;
else
incident.close_notes = msg + ": " + current.close_notes;
}
incident.close_code = current.close_code;
msg = "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;
incident.update();
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2018 12:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2018 12:20 AM
Hi Sandeep,
But it won't work if parent state changes to any other state other than resolved.
The requirement is to reflect all state changes and work notes change as well

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2018 12:44 AM
HI Aamir,
Please change your condition
from current.incident_state.changesTo(IncidentState.RESOLVED)
to current.incident_state.changes()
Then it will work
Please mark helpful or correct if it helps you.
REgards
SAndeep