Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Checking off linked record checkboxes via an Airtable script
// get the two tables I need to work on
let jobsTable = base.getTable("Jobs");
let timeEntriesTable = base.getTable("Time Entries");
// get all time entries for later reference
let timeEntriesQuery = await timeEntriesTable.selectRecordsAsync();
// when run via button, automatically use that record otherwise choose
let record = await input.recordAsync('Choose a record', jobsTable);
// get all linked time entries for record
let linkedTimeEntries = record.getCellValue("Time Entries") || [];
output.text("Found " + linkedTimeEntries.length + " total time entries");
// loop over all time entries for record
if (linkedTimeEntries.length > 0) {
for (let i = 0; i < linkedTimeEntries.length; i++) {
let record = timeEntriesQuery.getRecord(linkedTimeEntries[i].id)
// if time entry not invoiced
if (!record.getCellValue("Invoiced")) {
// check "Invoiced"
await timeEntriesTable.updateRecordAsync(record.id, {
"Invoiced": true,
});
output.text("✅ " + record.getCellValue("Date"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment