Nov 09, 2021 05:35 AM
Hi,
I need to iterate and create multiple linked records in table2 from table1 (without selecting them). But when I run my code I get the following error: “Can’t create records: invalid cell value for field ‘Property’.
Cell value has invalid format: .0.0 must be an object.
Linked records field value must be an array of objects with property ‘id’ corresponding to linked record id.”
I assume I have to put the linked record id in the createRecordAsync function, but I don’t know how the syntax for that should be.
Here is the full code. Thank you!
let importTable = base.getTable('Master List');
let importView = importTable.getView('Active View');
let importQuery = await importView.selectRecordsAsync();
let secondTable = base.getTable('Table2');
for (let record of importQuery.records) {
let fullName = record.getCellValue('Name');
await peopleTable.createRecordAsync({
"Person": fullName
})
output.text(`New record for ${fullName} created!`);
}
Solved! Go to Solution.
Nov 09, 2021 06:03 PM
The syntax requires an array of objects, each object would have a single key-value pair of the record ID. With your current code that would be:
await peopleTable.createRecordAsync({
"Person": [{id: record.id}]
})
You probably want to create multiple records at once for efficiency. That would mean replacing the for
loop with something like:
let updates = importQuery.recordIds.map(id => {
return {
fields: {
"Person": [{id: id}]
}
}
})
while (updates.length > 0) {
await secondTable.createRecordsAsync(updates.slice(0, 50))
updates = updates.slice(50)
}
Nov 09, 2021 06:03 PM
The syntax requires an array of objects, each object would have a single key-value pair of the record ID. With your current code that would be:
await peopleTable.createRecordAsync({
"Person": [{id: record.id}]
})
You probably want to create multiple records at once for efficiency. That would mean replacing the for
loop with something like:
let updates = importQuery.recordIds.map(id => {
return {
fields: {
"Person": [{id: id}]
}
}
})
while (updates.length > 0) {
await secondTable.createRecordsAsync(updates.slice(0, 50))
updates = updates.slice(50)
}
Nov 10, 2021 04:43 AM
This was super helpful. Thank you!
Jun 05, 2023 12:21 AM