I have two tables: Contacts and Companies
Multiple Contacts can be linked to Company record.
Both share the same “Application ID” Field.
For some reason when I run the script only handful of records are linked.
The linked field is the “Company” field in the “Contacts” table.
//Define the company table and query
let cmpTbl = base.getTable("Contacts");
let cmpQuery = await cmpTbl.selectRecordsAsync();
//Define contact table and query
let cntTbl = base.getTable("Companies");
let cntQuery = await cntTbl.selectRecordsAsync();
//Loop through the records and find the Contact ID
for (let record of cmpQuery.records) {
let cmpid = record.getCellValue("Application ID");
//Loop through linked table and match ID values
for (let cntRecord of cntQuery.records) {
if (cntRecord.getCellValue("Application ID") === cmpid) {
//Update field
cmpTbl.updateRecordAsync(record, {
'Company': [{id: cntRecord.id}]
});
}
}
}