Skip to content

Commit e06a954

Browse files
authored
script.js
1 parent de3ed58 commit e06a954

File tree

1 file changed

+29
-0
lines changed
  • Server-Side Components/Background Scripts/Update Parent Incident State To Closed If All Child Incident Is Closed

1 file changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(function() {
2+
var parentSysId = 'a83820b58f723300e7e16c7827bdeed2'; // Replace with actual parent incident sys_id
3+
var childIncidents = new GlideRecord('incident');
4+
childIncidents.addQuery('parent_incident', parentSysId);
5+
childIncidents.query();
6+
var allClosed = true;
7+
while (childIncidents.next()) {
8+
if (childIncidents.state != 7) { // 7 = Closed
9+
allClosed = false;
10+
gs.info("Child incident " + childIncidents.number + " is still open.");
11+
}
12+
}
13+
if (allClosed) {
14+
var parent = new GlideRecord('incident');
15+
if (parent.get(parentSysId)) {
16+
parent.state = 7; // Closed
17+
parent.close_code = 'Duplicate'; // Adjust to valid closure code in your instance
18+
parent.close_notes = 'Automatically closed since all child incidents are closed.';
19+
parent.setWorkflow(false); // Prevent triggering BRs/workflows
20+
parent.update();
21+
22+
gs.info("Parent incident [" + parent.number + "] has been closed automatically.");
23+
} else {
24+
gs.warn("Parent incident not found for sys_id: " + parentSysId);
25+
}
26+
} else {
27+
gs.info("Parent not closed because one or more child incidents are still open.");
28+
}
29+
})();

0 commit comments

Comments
 (0)