Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshbduncan/10b7f448e984e238fdbfa3fc95ebc1e6 to your computer and use it in GitHub Desktop.
Save joshbduncan/10b7f448e984e238fdbfa3fc95ebc1e6 to your computer and use it in GitHub Desktop.
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