Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Safe Bulk Record Update with Logging

## Overview
Efficiently update multiple records in batch with error handling, progress tracking, and logging to prevent timeouts and data loss.

## What It Does
- Updates records in configurable batch sizes
- Logs progress for monitoring
- Handles individual record errors without stopping batch
- Prevents script timeout with batch processing
- Tracks success/failure counts
- Logs detailed error information

## Use Cases
- Bulk data migrations
- Mass field updates after deployment
- Scheduled bulk corrections
- Data cleanup operations
- Batch status updates across records

## Files
- `bulk_update_with_progress.js` - Background Script for safe bulk updates

## How to Use

### Option 1: Run as Background Script
1. Go to **System Diagnostics > Script Background**
2. Copy code from `bulk_update_with_progress.js`
3. Modify the table name and query filter
4. Execute and monitor logs

### Option 2: Create as Scheduled Job
1. Go to **System Scheduler > Scheduled Jobs**
2. Create new job with the script code
3. Schedule for off-peak hours
4. Logs will be available in System Logs

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var TABLE = 'incident'; // Change to your table
var FILTER = "priority=1"; // Add your filter conditions
var FIELD_TO_UPDATE = 'state'; // Field to update
var NEW_VALUE = '1'; // Value to set

var successCount = 0;
//using gs.info for best logging
gs.info('[Bulk Update Started] Table: ' + TABLE + ' | Filter: ' + FILTER, 'BulkUpdate');

try {
var gr = new GlideRecord(TABLE);
gr.addEncodedQuery(FILTER);
gr.query();

// Collect all record IDs first (single query)
var recordIds = [];
while (gr.next()) {
recordIds.push(gr.getUniqueValue());
}

//using updateMultiple will update all records at once
if (recordIds.length > 0) {
var updateGr = new GlideRecord(TABLE);
updateGr.addEncodedQuery(FILTER);
updateGr.setValue(FIELD_TO_UPDATE, NEW_VALUE);
updateGr.updateMultiple();//this is more efficient
successCount = recordIds.length;
gs.info('[Bulk Update Complete] Total Updated: ' + successCount, 'BulkUpdate');
} else {
gs.info('[Bulk Update] No records matched the filter criteria', 'BulkUpdate');
}
} catch (e) {
gs.error('[Bulk Update Error] ' + e.toString(), 'BulkUpdate');
}
Loading