Sep 15, 2022 07:36 AM
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,
},
},
]);
}
Solved! Go to Solution.
Sep 26, 2022 08:29 PM
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}];
Sep 26, 2022 08:29 PM
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}];