Skip to content
← All scripts
Background scriptglobal scopeReview before use · not yet release-tested

Batch-update records safely from a background script

Update thousands of records in controlled batches, with a dry-run switch and logging, so you can see the impact before you commit.

October 1, 2026 · #gliderecord #bulk-update #performance

Bulk fixes are where background scripts cause the most damage. This pattern limits each run, supports a dry run, and logs exactly what changed.

var DRY_RUN = true; // set to false to write changes
var BATCH_SIZE = 500; // re-run until it reports 0

var gr = new GlideRecord('incident');
gr.addEncodedQuery('state=6^resolved_at<javascript:gs.daysAgoStart(30)');
gr.setLimit(BATCH_SIZE);
gr.query();

var count = 0;
while (gr.next()) {
  count++;
  if (DRY_RUN) {
    gs.info('[dry run] would close ' + gr.getValue('number'));
    continue;
  }
  gr.setValue('state', 7); // Closed
  gr.setWorkflow(false); // skip business rules and notifications
  gr.update();
}
gs.info((DRY_RUN ? '[dry run] ' : '') + count + ' records processed.');

How it works

  • setLimit() caps each run, so a mistake affects at most one batch.
  • DRY_RUN logs what would change without writing anything. Always run it first.
  • setWorkflow(false) stops business rules, notifications and audit-driven side effects for the update.

Gotchas

  • setWorkflow(false) also skips rules you may want, like ones that keep related records in sync. Decide deliberately.
  • Run it in a sub-production instance first, then capture the change in an update set or document it.
  • Large tables: keep the query on indexed fields where possible.

MIT licence. Provided as-is, without warranty. Test in a sub-production instance first.

Related scripts

Background scriptglobal

GlideDateTime: date maths you can trust

Add and subtract days, compare dates and measure durations with GlideDateTime, avoiding the time-zone mistakes that break date logic.

#glidedatetime #dates #scripting