Help

Upcoming database upgrades. to improve our reliability at 03:30 UTC on Feb. 25 / 7:30pm PT on Feb. 24. Some users may briefly experience slow load times or error messages. Learn more here

Mass-deletion from a linked field

Solved
Jump to Solution
487 2
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

1 Solution

Accepted Solutions

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

See Solution in Thread

2 Replies 2

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.