Created
August 4, 2021 17:42
-
-
Save joshbduncan/10b7f448e984e238fdbfa3fc95ebc1e6 to your computer and use it in GitHub Desktop.
Checking off linked record checkboxes via an Airtable script
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
// 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