Hello all,
I found the “Create child linked records” script and it does exactly what I need to do, but I want to trigger it from within an automation, and instead of entering the number of child records, pull that information in from the input.config() from the trigger of the automation.
I have a parent table called “ListInfo” and a child table called “List”. The primary key of the of the parent table is a field called “ListName”. The child table has a linked field also called “ListName”.
I would like this automation to create the “ListSize” number of child records in the child table each time a record in the parent table is created and meets the triggering conditions of the automation (the “ListName” is not empty, the “ListSize” is not empty and the record was created today) .
My input variables for the automation are “parentRecord” with a value of the record ID of the triggering record in the parent table and “newRecordCount” with a value of “ListSizeNum” which is a formula field that gives a value for the “ListSize” field since this is a linked field.
Here’s my latest attempt at an iteration to get this to work, to no avail.
let parenttbl = base.getTable('ListInfo');
let childtbl = base.getTable('List');
let {parentRecord,newRecordCount} = input.config();
let linkField = parenttbl.getField('ListName'):childtbl.getField('ListName');
async function createChildrenLinkedRecords() {
// Airtable limits batch operations to 50 records or fewer.
let maxRecordsPerCall = 50;
let newRecords = 5];
// Part 1: Prepare the new records
for (let index = 0; index < newRecordCount; index += 1) {
newRecords.push({
fields: {
linkField.id]: d{ id: parentRecord.id }],
},
});
}
// Part 2: Perform the record creation operations in batches
while (newRecords.length > 0) {
await childtbl.createRecordsAsync(newRecords.slice(0, maxRecordsPerCall));
newRecords = newRecords.slice(maxRecordsPerCall);
}
}
await createChildrenLinkedRecords();
Any pointers on what can be modified to get this to work are greatly appreciated.
Thanks!
Tom_H