I solved my own issue, here’s how:
First, I needed an await
keyword before the call to updateRecordAsync
.
Then, I also had to change the for loop so that it was a for (let i in newRecords)
rather than a forEach
. Not doing so gave me an error with the await
keyword.
Finally, the for (let i in newRecords)
gave me an index, rather than the record object, so I had to make sure I was indexing into the newRecords
array.
Final code that works (but is very slow):
let oldTable = base.getTable("Updated 4/15/21");
let newTable = base.getTable("Imported 4/29/21");
let oldRecordsQuery = await oldTable.selectRecordsAsync();
let newRecordsQuery = await newTable.selectRecordsAsync();
let oldRecords = oldRecordsQuery.records;
let newRecords = newRecordsQuery.records;
for (let i in newRecords) {
let record = newRecords[i];
let found = oldRecords.find((old) => old.name === record.name);
console.log(found);
if (found) {
let newCalledBy = found.getCellValueAsString("Called By");
let newCalled = found.getCellValue("Called?");
let newTexted = found.getCellValue("Texted?");
let newNotes = found.getCellValueAsString("Notes");
await newTable.updateRecordAsync(record, {
"Called By": newCalledBy,
"Called?": newCalled,
"Texted?": newTexted,
"Notes": newNotes,
});
}
};