Oct 12, 2023 09:27 AM
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?
Solved! Go to Solution.
Oct 12, 2023 11:25 AM
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);
}
Oct 12, 2023 11:25 AM
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);
}
Oct 12, 2023 12:18 PM
Thank you @Ben_YoungV2. The script worked!