- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2025 05:26 AM
Don't Know why its not working.
Want not closed incident if child incident is open.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2025 07:26 AM
Hello @arshadansar ,
Ok, got it, thanks. Please update your Business Rule script as follows:
(function executeRule(current, previous /*null when async*/ ) {
var childTask = new GlideRecord('incident');
childTask.addQuery('parent_incident', current.getUniqueValue());
childTask.addQuery('state', '!=', '7'); // not closed
childTask.query();
var arr = [];
while (childTask.next()) {
arr.push(childTask.getValue('number'));
}
if (arr.length > 0) {
gs.addErrorMessage('Cannot update the parent Incident until all child Incidents are closed: ' + arr.join(', '));
current.state = previous.state;
current.incident_state = previous.incident_state;
current.setAbortAction(true);
}
})(current, previous);
And make sure the BR "When" field is set to "before", not "after".
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2025 06:47 AM - edited 05-24-2025 06:53 AM
Hello @arshadansar ,
I don't understand the question.
You have a Business Rule that prevents closing an Incident if it has open child Incidents.
And your screen shots are demonstrating that it's working fine: your Incident 8112 has two open child Incidents, that's why you cannot close it. Once you close these two Incidents your Business Rule will allow you to close the parent Incident.
PS: the second GlideRecord query is unnecessary. Instead of "if (childTask.hasNext())" you can do "while (childTask.next())" and populate the array right away. And then add an "if (arr.length > 0)" at the end to check if you need to print the message and abort the action.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2025 06:59 AM
All Work Fine But when i try to close parent incident it show me message that you can't close parent incident but after it state changes to close that i don't want to update state if child is present.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2025 07:12 AM - edited 05-24-2025 07:14 AM
Hi @arshadansar
I hope it's changed only in the UI. If you refresh the screen, the state will revert to "Resolved" state.
If not, then try the below script...
(function executeRule(current, previous /*null when async*/ ) {
var records = new GlideRecord('incident');
records.addQuery('parent_incident', current.sys_id);
records.addQuery('state', '!=', 7); // 7 is the state for 'Closed'
records.setLimit(1);
records.query();
if (records.hasNext()) {
var childrenIncidentNumbers = [];
while (records.next()) {
childrenIncidentNumbers.push(records.getValue('number'));
}
gs.addErrorMessage('Cannot update parent incident ' + current.number + ' as there are open children incidents: ' + childrenIncidentNumbers.join(', '));
current.setAbortAction(true);
}
})(current, previous);
Regards ,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2025 07:26 AM
Hello @arshadansar ,
Ok, got it, thanks. Please update your Business Rule script as follows:
(function executeRule(current, previous /*null when async*/ ) {
var childTask = new GlideRecord('incident');
childTask.addQuery('parent_incident', current.getUniqueValue());
childTask.addQuery('state', '!=', '7'); // not closed
childTask.query();
var arr = [];
while (childTask.next()) {
arr.push(childTask.getValue('number'));
}
if (arr.length > 0) {
gs.addErrorMessage('Cannot update the parent Incident until all child Incidents are closed: ' + arr.join(', '));
current.state = previous.state;
current.incident_state = previous.incident_state;
current.setAbortAction(true);
}
})(current, previous);
And make sure the BR "When" field is set to "before", not "after".
Regards,
Robert