Need a script for when parent incident closes, related child incidents shold close automatically.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2019 05:31 AM
Need a script for when parent incident closes, related child incidents shold close automatically.
Please explain with example
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2019 05:41 AM
try with below script.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
// Query for associated records related to the same parent
var inc = new GlideRecord('incident');
inc.addQuery('parent_incident', current.sys_id);
inc.addActiveQuery();
inc.query();
while(inc.next()) {
inc.state = 7; // Close the incident
inc.active = false;
inc.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2019 05:44 AM
also want to add here, there is already ootb business rule which does this.
Business Rule Name : Update Child Incidents
try to have a look that business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2019 05:45 AM
Hi,
You want to do something like this in an after update business rule:
var children = new GlideRecord("incident");
children.addQuery("parent", current.sys_id);
children.query();
while (children.next()) {
children.state = 7;
children.close_code = current.close_code;
children.close_notes = current.close_notes;
children.update();
}
This will not only close the children, it will also give them the notes and code from the parent. This will apply to all child incidents even if some may already be closed if you want to avoid that you can add:
children.addQuery("state", "<", 6);
before the query. This will look for anything that hasn't been resolved, closed or cancelled. To include resolved incidents change the 6 to a 7.
Hope that helps.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
:{)
Helpful and Correct tags are appreciated and help others to find information faster