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