Skip to content

Instantly share code, notes, and snippets.

@estelsmith
Created February 16, 2023 21:02
Show Gist options
  • Save estelsmith/a5cfda9c6cd2abc891b5396cd9fae4be to your computer and use it in GitHub Desktop.
Save estelsmith/a5cfda9c6cd2abc891b5396cd9fae4be to your computer and use it in GitHub Desktop.
Airtable Scripting - Conditionally update records based on view
let config = input.config({
title: 'Test Script',
description: 'Updates Name & Email fields on Test records to have a generic default if they are empty.',
items: []
});
let table = base.getTable('Test');
let view = table.getView('Empty Name or Email');
let result = await view.selectRecordsAsync({
fields: ['ID', 'Name', 'Email']
});
for (let record of result.records) {
let id = record.getCellValue('ID');
let name = record.getCellValue('Name');
let email = record.getCellValue('Email');
output.text(`processing ${id}`);
if (name === null || name === '') {
await table.updateRecordAsync(record, {Name: 'Unnamed Person'});
output.text(`update ${id} name`);
}
if (email === null || email === '') {
await table.updateRecordAsync(record, {Email: 'unnamed@test.com'});
output.text(`update ${id} email`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment