Hi!
I’m working on an airtable script where I’m trying to re-link records that were previously linked in another base.
Context: I shared two tables from an OLD base to a NEW base. These tables had records that were linked(in the old base). After sharing them to the NEW base, the links got lost. I’m now trying to re-link these records. I have two tables, “Companies” and “People”. The “Companies” table has fields with the company name and employees. The “People” table has fields with people’s names and their affiliated company.
Here’s the script I have written to attempt to solve this issue.
//Define the company table and query
let cmpTbl = base.getTable("Companies");
let cmpQuery = await cmpTbl.selectRecordsAsync();
console.log(cmpQuery)
//Define people table and query
let pplTbl = base.getTable("People");
let pplQuery = await pplTbl.selectRecordsAsync();
console.log(pplQuery)
for (let allPeople of pplQuery.records){
let cmp = allPeople.getCellValue("Company")
console.log(cmp)
for (let allCompanies of cmpQuery.records){
if (cmp === allCompanies.getCellValueAsString("Company")) {
// console.log(cmp)
// console.log(allCompanies.getCellValueAsString("Company"))
let cmpID = allCompanies.id
await pplTbl.updateRecordAsync(allPeople, {"Company" : c{id: cmpID}]})
}
}
}
I essentially loop through the “People” table and extract the corresponding string value in the company field and compare that to the records in the “Companies” table after which I go ahead and link them. However, there’s an error:
any ideas on how to fix this issue? Seems like a fieldType issue but I have tried casting the ‘string’ ID to an Airtable_record.id and it hasn’t worked.