Created
February 16, 2023 21:02
-
-
Save estelsmith/a5cfda9c6cd2abc891b5396cd9fae4be to your computer and use it in GitHub Desktop.
Airtable Scripting - Conditionally update records based on view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '[email protected]'}); | |
output.text(`update ${id} email`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment