File tree Expand file tree Collapse 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 Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 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+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments