Mass-deletion from a linked field

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.

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})

Thanks Kamille, that worked fine.

This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.