
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 13, 2022 11:17 AM
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" : [{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.
Solved! Go to Solution.
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 13, 2022 02:01 PM
Your “Company” field is presumably a Single Line Text, right? If it were already a Link Field, then your records were already linked and there’d be no need for the script.
You can’t pass an array or object to a Text field. You have to pass a string.
If the name of the Company is the primary field of the Companies table, and your People table has a field where companies are comma separated, then just convert that field into a Link Records field. The old text field in Companies that lists People will be redundant, so you can delete it. Airtable will have created a new inverse-Link Field inside your Companies table upon field conversion.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 13, 2022 02:01 PM
Your “Company” field is presumably a Single Line Text, right? If it were already a Link Field, then your records were already linked and there’d be no need for the script.
You can’t pass an array or object to a Text field. You have to pass a string.
If the name of the Company is the primary field of the Companies table, and your People table has a field where companies are comma separated, then just convert that field into a Link Records field. The old text field in Companies that lists People will be redundant, so you can delete it. Airtable will have created a new inverse-Link Field inside your Companies table upon field conversion.
