Skip to content

Commit 26ec6f0

Browse files
committed
docs: Updated bulk update script
1 parent 223bb7b commit 26ec6f0

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
// Background Script: Safe Bulk Record Update with Progress Tracking
2-
// Purpose: Update multiple records efficiently using updateMultiple()
3-
41
var TABLE = 'incident'; // Change to your table
52
var FILTER = "priority=1"; // Add your filter conditions
63
var FIELD_TO_UPDATE = 'state'; // Field to update
74
var NEW_VALUE = '1'; // Value to set
85

96
var successCount = 0;
107
var errorCount = 0;
11-
8+
//using gs.info for best logging
129
gs.info('[Bulk Update Started] Table: ' + TABLE + ' | Filter: ' + FILTER, 'BulkUpdate');
1310

1411
try {
@@ -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

Comments
 (0)