Help

Adding linked records in script

Topic Labels: Automations
Solved
Jump to Solution
1571 2
cancel
Showing results for 
Search instead for 
Did you mean: 
ShlomoGreen
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi all,

I'm writing after thoroughly searching the forum and endless tries, so I really hope someone can help here...

My scripting abilities are very basic but i can read and understand it, and can even write it with the help of GPT 😅

As part of a multistep automation, I'm running a script that takes apart a poorly formatted text field from my "form" table (using input.config) and creates multiple new records in my "contacts" table. The script works well and the new contacts are being created with all of the relevant text fields in the new table.

My issues began when I tried populating other types of fields.. After lots of searching I fingered out that to update a single select filed it needs to be an object, and i finally managed to do that.

Like this:

 

 

 

  record['Marital Status'] = { name: 'Single' };

 

 

 

I'm now trying to link another table to these new created contacts. This is the "Families" table and it is already referenced previously in my automation. So I set up another input filed with the "families" airtable record ID  and i'm calling it via a new const called "FamilyToConnect ", but no matter what i try, it won't update the linked record in the new "contact" record.

I've tried:

 

 

 

record['Family'] = [{ id: FamilyToConnect }];

record['Family'] = { id: FamilyToConnect };

record['Family'] = [ id: FamilyToConnect ];

record['Family] = [{ id: FamilyToConnect, fields: {} }];

 

 

Non of those worked (but no error)
 
I then thought possibly the issue is I'm trying to link a record before the record has been created so i stored the new record first, then tried to update the linked field, like this:
 

 

 

for (const createdRecord of createdRecords) {
  const updateRecord = {
    id: createdRecord.id,
    fields: {
      'Family': [{ id: FamilyToConnect }],
    }

 

 

Still no go.

 

I'm sure I'm missing some simple knowledge here but cant figure it out.

Any help is much appreciated!

1 Solution

Accepted Solutions
ShlomoGreen
5 - Automation Enthusiast
5 - Automation Enthusiast

In case  anyone finds themselves in the same situation...
I found the answers here: https://airtable.com/developers/scripting/api/cell_values

 

See Solution in Thread

2 Replies 2
ShlomoGreen
5 - Automation Enthusiast
5 - Automation Enthusiast

So, i've made some progress I realize I'm getting an array and need to extract the actual record ID (there will always only be one record ID in the array). So, i did this:

  record['Family] = {id: FamilyToConnect.toString()};

 

 

but it's still not working... It feels like I'm really close but not quite there yet...

 

 

ShlomoGreen
5 - Automation Enthusiast
5 - Automation Enthusiast

In case  anyone finds themselves in the same situation...
I found the answers here: https://airtable.com/developers/scripting/api/cell_values