File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed
Server-Side Components/Business Rules/Validate Checklist items Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change 1- //Business Rule: before update on the incident table
2- //Condition: changing state to 'In Progress'
1+ // Business Rule: Before Update on Incident table
2+ // Condition: current.state == 2 (In Progress)
3+
34( function executeRule ( current , previous /*null when async*/ ) {
4- var checklistGR = new GlideRecord ( "checklist" ) ;
5- checklistGR . addQuery ( "document" , current . sys_id ) ;
6- checklistGR . query ( ) ;
5+ // Only run if state is changing to 'In Progress'
6+ if ( current . state == 2 && previous . state != 2 ) {
77
8- while ( checklistGR . next ( ) ) {
8+ // Query checklist items tied to this record that are not complete
99 var itemGR = new GlideRecord ( "checklist_item" ) ;
10- itemGR . addQuery ( "checklist " , checklistGR . sys_id ) ;
11- itemGR . addQuery ( "complete" , false ) ;
10+ itemGR . addQuery ( "document " , current . sys_id ) ; // Matches the current record
11+ itemGR . addQuery ( "complete" , false ) ; // Only incomplete items
1212 itemGR . query ( ) ;
1313
14+ // If any incomplete item exists, abort the action
1415 if ( itemGR . hasNext ( ) ) {
15- gs . addErrorMessage ( 'Checklist has incomplete items. Please complete all before assigning it back.' ) ;
16+ gs . addErrorMessage ( "This record has incomplete checklist items. Please complete them before proceeding." ) ;
1617 current . setAbortAction ( true ) ;
1718 }
1819 }
1920} ) ( current , previous ) ;
21+
You can’t perform that action at this time.
0 commit comments