Mar 30, 2021 03:11 PM
Hello community,
I’m as stuck as that cargo ship in Suez, if you know what I mean :ship:
I have a table T1 linked to a table T2:
T1 → (link field:‘T2records’) → T2
I need to delete all linked records in T2 at once, using the link field on T1. I’m trying something like this:
let linkedT2records = T1record.getCellValue('T2records');
let T2recordsIds = linkedT2records.map(T2record => {
return { id: T2record.id };
})
await T2.deleteRecordsAsync(T2recordsIds);
Script checker flags the parameter in the delete command and pops up:
Argument of type '{ id: string; }[]' is not assignable to parameter of type '(string | T2Table_Record)[]'.
And if executed, it halts there throwing:
TypeError: Invalid arguments passed to table.deleteRecordsAsync(recordsOrRecordIds):
• recordsOrRecordIds[0] should be a Record, not an object
or recordsOrRecordIds[0] should be a string, not an object
The syntax definition for deleteRecordsAsync reads:
async function (recordsOrRecordIds: Array<Record | string>)
It seems I fail to arrange the T2 records IDs present in the linked field, in the proper format expected for deleteRecordsAsync.
Can someone please show me the way to correctly map the T2 record IDs for deleteRecordsAsync?
Thanks for your assistance.
Solved! Go to Solution.
Mar 30, 2021 05:51 PM
You need to give .deleteRecordsAsync()
an array of record IDs, you have given it an array of objects where each object contains one key/value pair ({id: 'some record id'}
).
Simplify your .map()
to .map(T2record => {return T2record.id})
Mar 30, 2021 05:51 PM
You need to give .deleteRecordsAsync()
an array of record IDs, you have given it an array of objects where each object contains one key/value pair ({id: 'some record id'}
).
Simplify your .map()
to .map(T2record => {return T2record.id})
Mar 31, 2021 08:04 AM
Thanks Kamille, that worked fine.