1- // Background Script: Safe Bulk Record Update with Progress Tracking
2- // Purpose: Update multiple records efficiently using updateMultiple()
3-
41var TABLE = 'incident' ; // Change to your table
52var FILTER = "priority=1" ; // Add your filter conditions
63var FIELD_TO_UPDATE = 'state' ; // Field to update
74var NEW_VALUE = '1' ; // Value to set
85
96var successCount = 0 ;
107var errorCount = 0 ;
11-
8+ //using gs.info for best logging
129gs . info ( '[Bulk Update Started] Table: ' + TABLE + ' | Filter: ' + FILTER , 'BulkUpdate' ) ;
1310
1411try {
@@ -22,19 +19,17 @@ try {
2219 recordIds . push ( gr . getUniqueValue ( ) ) ;
2320 }
2421
25- // Update all records at once using updateMultiple
22+ //using updateMultiple will update all records at once
2623 if ( recordIds . length > 0 ) {
2724 var updateGr = new GlideRecord ( TABLE ) ;
2825 updateGr . addEncodedQuery ( FILTER ) ;
2926 updateGr . setValue ( FIELD_TO_UPDATE , NEW_VALUE ) ;
30- updateGr . updateMultiple ( ) ;
31-
27+ updateGr . updateMultiple ( ) ; //this is more efficient
3228 successCount = recordIds . length ;
3329 gs . info ( '[Bulk Update Complete] Total Updated: ' + successCount , 'BulkUpdate' ) ;
3430 } else {
3531 gs . info ( '[Bulk Update] No records matched the filter criteria' , 'BulkUpdate' ) ;
3632 }
37-
3833} catch ( e ) {
3934 gs . error ( '[Bulk Update Error] ' + e . toString ( ) , 'BulkUpdate' ) ;
4035}
0 commit comments