Help

Re: Scripted Automation for deleting records timing out

Solved
Jump to Solution
1028 0
cancel
Showing results for 
Search instead for 
Did you mean: 
AJ
4 - Data Explorer
4 - Data Explorer

let table = base.getTable("Customer Survey Prod");
let field = table.getField("Aged Days");
let query = await table.selectRecordsAsync({fields: [field]});
let recordsToDelete = query.records.filter(
record => record.getCellValue(field) > 7
)
console.log(recordsToDelete);
for (let deleteRecord of recordsToDelete) {
await table.deleteRecordAsync(deleteRecord.id);
}

I am running into a 30 minute error when running this is there a way to fix it?

1 Solution

Accepted Solutions
Ben_YoungV2
5 - Automation Enthusiast
5 - Automation Enthusiast
const table = base.getTable('Customer Survey Prod');
const field = 'Aged Days';


const filterRecord = (record) => record.getCellValue(field) > 7;

const deleteRecords = async (records) => {

    let targetRecords = records;

    while (targetRecords.length) {
        await table.deleteRecordsAsync(targetRecords.slice(0, 50));
        targetRecords = targetRecords.slice(50);
    }
}


let records = await table.selectRecordsAsync({ fields: [field] })
.catch(err => console.log(err))
.then(query => query.records);


let recordsToDelete = records.filter(filterRecord);

if (recordsToDelete.length) {
    await deleteRecords(recordsToDelete);
}

See Solution in Thread

2 Replies 2
Ben_YoungV2
5 - Automation Enthusiast
5 - Automation Enthusiast
const table = base.getTable('Customer Survey Prod');
const field = 'Aged Days';


const filterRecord = (record) => record.getCellValue(field) > 7;

const deleteRecords = async (records) => {

    let targetRecords = records;

    while (targetRecords.length) {
        await table.deleteRecordsAsync(targetRecords.slice(0, 50));
        targetRecords = targetRecords.slice(50);
    }
}


let records = await table.selectRecordsAsync({ fields: [field] })
.catch(err => console.log(err))
.then(query => query.records);


let recordsToDelete = records.filter(filterRecord);

if (recordsToDelete.length) {
    await deleteRecords(recordsToDelete);
}
AJ
4 - Data Explorer
4 - Data Explorer

Thank you @Ben_YoungV2. The script worked!