Help

Re: Delete Records and extend script execution

1226 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Marc_Justin_Rai
6 - Interface Innovator
6 - Interface Innovator

Hello, I’m trying to delete a massive duplicate records in my table about 10,000 to 20,000 records exist in my table. As i don’t know where to insert the proper condition if the records is duplicate by knowing they are older dates or not up-to-date/current date And I can’t delete them in one go due to script execute time.

// Read our table
var table = base.getTable("Weekly Metrics");
var query = await table.selectRecordsAsync ();
// Check whether any record in that table
// match the input 
let duplicate = query.records.filter((record)=>{
    return query.records.find((potentialDuplicate) => {
    return record.getCellValue("Pages") === potentialDuplicate.getCellValue("Pages") && record.id !== potentialDuplicate.id;
    //&& record.id !== potentialDuplicate.Id
    })
});
// console.log(duplicate);
let updates = duplicate.map(update => {
    return {
        "id":update.id,
        fields:{
            "Duplicate?":true
        }
    }
});
while(updates.length > 0){
    await table.updateRecordsAsync(updates.slice(0,50));
    updates.slice(50);
}
12 Replies 12

That’s not really how .map is designed to be used. It is for mapping one array onto a different array. You shouldn’t be deleting records in the array as part of the mapping process.

Hello miss @kuovonne, is it possible to use the updateRecordAsync from base1 but the data will be put to base2. like base2.updateRecordAsync

No. Scripting is designed to only affect the base in which the script resides. There are workarounds that involve accessing the REST API, webhooks, or third party tools to affect change in a different base. All of these workarounds add a layer of complexity.