Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Business Rule: Auto-Close Incident When All Related Changes Are Closed
Table : change_request
When to Run: After update
Condition: state changes to Closed (or your equivalent "Closed" state number, e.g. state == 3)

Detailed Working
1. Trigger Point
This After Business Rule runs after a Change Request record is updated.
Specifically, it checks when the state changes to “Closed”.

2. Check for Related Incident
The script retrieves the incident reference field (incident) from the current change request.
If there’s no linked incident, it skips execution.

3. Check for Any Remaining Open Change Requests
A new GlideRecord query checks for other Change Requests linked to the same incident where:
If any such records exist, it means not all change requests are closed — so the incident remains open.

4. Close the Incident Automatically
If no open Change Requests remain, the script:
Fetches the linked incident.
Sets: state = 7 (Closed)
close_code = Auto Closed
close_notes = Auto closure as all changes are closed.
Updates the record.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(function executeRule(current, previous /*null when async*/) {
// Run only when change_request moves to Closed
if (current.state != previous.state && current.state == 3) { // 3 = Closed
var incidentSysId = current.incident; // assuming there is a reference field to Incident

if (!incidentSysId) {
gs.info("No related incident found for this change request: " + current.number);
return;
}

// Query for other open change requests linked to the same incident
var otherCR = new GlideRecord('change_request');
otherCR.addQuery('incident', incidentSysId);
otherCR.addQuery('sys_id', '!=', current.sys_id);
otherCR.addQuery('state', '!=', 3); // not closed
otherCR.query();

if (otherCR.hasNext()) {
gs.info("Incident " + incidentSysId + " still has open change requests. Not closing incident.");
return;
}

// If no open change requests remain, close the incident
var inc = new GlideRecord('incident');
if (inc.get(incidentSysId)) {
inc.state = 7; // 7 = Closed (modify as per your instance)
inc.close_code = 'Auto Closed';
inc.close_notes = 'Incident auto-closed as all associated change requests are closed.';
inc.update();
gs.info("Incident " + inc.number + " auto-closed as all related change requests are closed.");
}

}
})(current, previous);

Loading