Skip to main content
Solved

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

  • September 15, 2022
  • 1 reply
  • 2 views

Forum|alt.badge.img+3

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:

error message:

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,  
      },
    }, 
  ]);
}

Best answer by Justin_Barrett

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}];
View original
Did this topic help you find an answer to your question?

1 reply

Justin_Barrett
Forum|alt.badge.img+20
  • Inspiring
  • 4647 replies
  • Answer
  • September 27, 2022

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}];

Reply