Closing child Incidents of an Incident that is a child of a Problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2022 03:12 AM
We have a business rule that resolves child Incidents when the parent is resolved. We also have a business rule that resolves child Incidents when the parent problem is completed. What we can't seem to achieve is when the problem is completed, that cascades down to the child Incident and then the children of that Incident.
I guess I would like to know if a) this is expected behaviour and b) if it's not, how do I tackle this?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2022 03:54 AM
Hi,
Ideally it should cascade down child incident.
You would need to check if there is any BR or any script where there is setWorkFlow(false) written which might stopping this cascade.
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Regards,
Abhijit
ServiceNow MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2022 03:55 AM
Hi TJ,
A) OOTB on my PDI, no incident whether it be Parent/Child are resolved when the related problem changes to completed. I believe what you experience is expected.
B) You can achieve this with another business rule running on the problem table. Use the business you have that resolves child incidents when the parent problem is completed as a reference.
What you need to do is either extend that business rule or create a new one.
- When problem is updated to closed
- Get a list of 'parent' incidents
- Update parent incident to closed
- Iterate through the list of parent incidents and get their child incidents
- Update child incidents to closed
Heres one I created and tested in my PDI:
If you use this script, please test on a subset of records to ensure it's functioning as you'd like.
(function executeRule(current, previous /*null when async*/) {
var incidentGR = new GlideRecord('incident');
var incidentArray = [];
incidentGR.addActiveQuery();
incidentGR.addQuery('problem_id', 'current.sys_id');
incidentGR.query();
while(incidentGR.next()){
incidentArray.push(incidentGR); //array contains all 'parent' incidents
incidentGR.state = '7';
incidentGR.close_code = 'successful';
incidentGR.close_notes = 'closed via business rule';
incidentGR.update();
gs.log('adding incident to list: ' + incidentGR.number);
}
for(i = 0; i < incidentArray.length; i++){
var incidentChildGR = new GlideRecord('incident');
incidentChildGR.addQuery('parent_incident', incidentArray[i].sys_id);
incidentChildGR.query();
while(incidentChildGR.next()){
gs.log('found incident to close: ' + incidentChildGR.number + ' parent is: ' + incidentArray[i].number);
incidentChildGR.state = '7';
incidentChildGR.close_code = 'successful';
incidentChildGR.close_notes = 'closed via business rule';
incidentChildGR.update();
}
}
})(current, previous);
Please mark this answer as helpful/solved based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2022 03:31 AM
Morning Dan,
Cheers for your suggestion, it wouldn't work for me but it did help me get to a solution!
I've altered the OOB inactive BR and made some amendments to cater for our customisations and the child Incidents.
if (current.problem_state.changesTo(107)) {
resolveRelatedIncidents(current);
closeRelatedTasks(current);
}
//
// Close any incidents that are related to the current problem, including child Incidents
//
function resolveRelatedIncidents(me) {
var incident = new GlideRecord("incident");
incident.addQuery("problem_id", "=", me.sys_id);
incident.query();
while (incident.next()) {
if (incident.active == true) {
var msg = gs.getMessage("Incident {0} resolved based on closure of problem {1}", [incident.number, me.number]);
gs.print(msg);
incident.incident_state.setValue(IncidentState.RESOLVED);
incident.comments = msg;
incident.u_resolution_category = incident.category;
incident.u_resolution_subcategory = incident.subcategory;
incident.u_fix_category = me.u_fix_category;
incident.close_notes = "Fix notes from " + me.number + "\n" + GlideSPScriptable().stripHTML(me.fix_notes);
incident.update();
gs.log(incident.number + ": Resolved child Incident of " + me.number);
var childinc = new GlideRecord("incident");
childinc.addQuery("parent_incident", "=", incident.sys_id);
childinc.query();
while (childinc.next()) {
if (childinc.active == true) {
childinc.incident_state.setValue(IncidentState.RESOLVED);
childinc.comments = msg;
childinc.u_resolution_category = incident.u_resolution_category;
childinc.u_resolution_subcategory = incident.u_resolution_subcategory;
childinc.u_fix_category = incident.u_fix_category;
childinc.close_notes = incident.close_notes;
childinc.update();
gs.log(childinc.number + ": Resolved child Incident of " + incident.number + " from " + me.number);
}
}
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2022 05:52 AM
No problem, looks good!