Bulk update Airtable records with a script, safely
Short answer: before writing, preview the planned changes, save the old values somewhere you can read back, then update in batches of 50 (the Scripting extension's limit per call). If something looks wrong, the saved values let you roll back exactly.
The pattern
// Scripting extension. Edit TABLE, FIELD and newValue() for your case.
const TABLE = "Contacts", FIELD = "Status";
const DRY_RUN = true; // set to false to write
const table = base.getTable(TABLE);
const query = await table.selectRecordsAsync({fields: [FIELD]});
function newValue(rec) { // your rule here
return rec.getCellValueAsString(FIELD) === "lead" ? "contacted" : null;
}
const changes = [];
for (const r of query.records) {
const v = newValue(r);
if (v !== null) changes.push({id: r.id, old: r.getCellValueAsString(FIELD), new: v});
}
output.text(`${changes.length} records would change`);
output.table(changes.slice(0, 50)); // preview
if (!DRY_RUN) {
// keep the old values: copy this JSON into a long text field or a file
output.text(JSON.stringify(changes.map(c => ({id: c.id, old: c.old}))));
for (let i = 0; i < changes.length; i += 50) {
await table.updateRecordsAsync(changes.slice(i, i + 50)
.map(c => ({id: c.id, fields: {[FIELD]: {name: c.new}}})));
}
output.text("done");
}
The example writes a single select ({name: ...}). For a text field, write the string directly.
Rules that prevent disasters
- Dry run first. Read the count and the preview. If the count is surprising, stop.
- Only write the fields you mean to change. Fields not included in the update are left alone.
- Skip nulls. Decide explicitly whether "no new value" means "leave as is" (skip) or "clear".
- Keep the old values with record IDs. A rollback script is then the same loop with
oldinstead ofnew. - Snapshot first anyway, for anything the script didn't expect.
- Updates trigger "When record updated" automations. Pause them if you don't want hundreds of runs (Free includes only 100 runs a month).