Hello,
I'm working on an automation that, when triggered by a new record being created, runs a script. The script should take that record, parse a comma-delimited list, then create new records in a separate table. The new records are include the unique names, the count of each unique name, and a link back to the original record. I mostly have this sorted now thanks to some awesome older forum posts, but I'm having trouble understanding how to write new records.
The error I'm getting is on the last line of code where the records are being created:
I believe the issue is with how I'm assigning the records. I do not understand the correct syntax, so any help would be highly appreciated!
let inputConfig = input.config();
let fullnameList = inputConfig.fullnameList;
let sourceID = inputConfig.sourceID;
const uniquenames = [... new Set(fullnameList)]; //gets unique array elements see https://codeburst.io/javascript-array-distinct-5edc93501dc4
let nameTable = base.getTable('names');
let nameRecord = nameTable.records
let recordsToCreate = [];
for(let i=0; i<uniquenames.length; i++){ //check each unique name
let nameCount = 0;
let onename = uniquenames[i];
for(let j=0; j<fullnameList.length; j++){
let name_i = fullnameList[i];
if(onename == name_i){
nameCount += 1;
}
}
recordsToCreate.push(
{fields : {
"nameField" : onename,
"Part Count" : nameCount,
"Prints" : sourceID
}}
)
};
console.log(recordsToCreate);
await nameTable.createRecordsAsync(recordsToCreate);