Help

Discover what data silos are costing your org in our commissioned Forrester study. Learn more

Delete all records on schedule

Topic Labels: Automations
111 6
cancel
Showing results for 
Search instead for 
Did you mean: 

Hello !

So i have a base and i want to delete all records that are on the table every sunday (weekly).

i heard that it’s possible to do it with a script, but i don’t know how.

Can you help me please? Thanks

6 Replies 6

I don’t know Javascript, so somebody else will need to chime in to help you write a script that does this.

Alternatively, if you want a no-code way of deleting records on a schedule that doesn’t require any knowledge of coding or scripting, you could just use Make to do this.

It would be an extremely simple 2-step scenario that looks like the screenshot below:

image

Hi @Slim_BENAZIZA, you would create a new automation that runs every Sunday and the action would be the following script:

// LOAD TABLE
const table = base.getTable("[INSERT YOUR TABLE NAME]");
// LOAD ALL RECORDS IN THAT TABLE AND MAP ARRAY TO ONLY INCLUDE REC IDs
const records = await table.selectRecordsAsync().then(result => result.records.map(rec => rec.id);
// DELETE ALL RECORDS IN BATCHES OF 50 (AIRTABLE LIMIT) BY PASSING REC IDs
if(records) {
   while(records.length > 0) {
      await table.deleteRecordsAsync(records.slice(0,50));
      records = records.slice(50);
   }
}

I haven’t tested this in a base but it hopefully does the work :slightly_smiling_face: Otherwise please post here.

Hi @Rupert_Hoffschmidt

i did what you suggest, but when i test this script, i have an error:

Syntax error:
missing ) after argument list [script.js:7:97]

Sorry, missed a “)”:

// LOAD TABLE
const table = base.getTable("Table 3");
// LOAD ALL RECORDS IN THAT TABLE AND MAP ARRAY TO ONLY INCLUDE REC IDs
const records = await table.selectRecordsAsync().then(result => result.records.map(rec => rec.id));
// DELETE ALL RECORDS IN BATCHES OF 50 (AIRTABLE LIMIT) BY PASSING REC IDs
if(records) {
   while(records.length > 0) {
      await table.deleteRecordsAsync(records.slice(0,50));
      records = records.slice(50);
   }
}

Ah damn sorry — didn’t have more than 50 records when I tested!

// LOAD TABLE
const table = base.getTable("Table 3");
// LOAD ALL RECORDS IN THAT TABLE AND MAP ARRAY TO ONLY INCLUDE REC IDs
let records = await table.selectRecordsAsync().then(result => result.records.map(rec => rec.id));
// DELETE ALL RECORDS IN BATCHES OF 50 (AIRTABLE LIMIT) BY PASSING REC IDs
if(records) {
   while(records.length > 0) {
      await table.deleteRecordsAsync(records.slice(0,50));
      records = records.slice(50);
   }
}

Now it should work :slightly_smiling_face: