Help

Scripting Automation: Linking new records created in automation to existing records

Topic Labels: Scripting extentions
Solved
Jump to Solution
1214 1
cancel
Showing results for 
Search instead for 
Did you mean: 
SPRCHRGR_Airtab
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi, Airtable community!

I’m writing a script in the Automations tab. My first trigger creates a new record called newEntityId.
I want to link that newEntityId record to another record I’ve created in the script.

My problem is that you can only get the record ID from the newly created record and the field type I want to link to is “Link to another record” which requires the object/record type.

I’ve made a solution that works but throws an error. If the error could be solved, that would be appreciated!

new record:
image

error message:
image

Code:

let inputConfig = input.config();

let tasksTable = base.getTable("Tasks");
let taskQuery = await tasksTable.selectRecordsAsync();
let tasksrecords = taskQuery.records 

let tasksTemplate = base.getTable("Tasks Template");
let templateQuery = await tasksTemplate.selectRecordsAsync();
let tasksTemplateRecords = templateQuery.records;
let taskTemplateLength = templateQuery.records.length;  

//Create taskTemplate.length records in Tasks field AND add all tasks template to the array
let tasksArray = [];
for (let i = 0; i < taskTemplateLength; i++) {
  tasksArray[i] = await tasksTable.createRecordAsync({
  });

}

let newEntity = [{
    id: inputConfig.newEntityId,
    name: "",
}];

for (let i = 0; i < taskTemplateLength; i++) {
  await tasksTable.updateRecordsAsync([
    {
      id: tasksArray[i],
      fields: {
        "Task": [tasksTemplateRecords[i]],
        "Entities": newEntity,  
      },
    }, 
  ]);
}
1 Solution

Accepted Solutions
Justin_Barrett
18 - Pluto
18 - Pluto

Here’s where your problem lies. The correct format for creating a link to a record only includes the record ID. The “name” property that you added makes it invalid. This should work:

let newEntity = [{id: inputConfig.newEntityId}];

See Solution in Thread

1 Reply 1
Justin_Barrett
18 - Pluto
18 - Pluto

Here’s where your problem lies. The correct format for creating a link to a record only includes the record ID. The “name” property that you added makes it invalid. This should work:

let newEntity = [{id: inputConfig.newEntityId}];