Skip to main content
Solved

Delete entries based on condition


Forum|alt.badge.img+4

Dear All,

Newbie here! To simplify our current workspace, we would like to duplicate our main base (let's call it A) and delete any entries in the duplicated version (B) with a deadline after June 2023. B will be used as archive for our past work.


Then we would like to run an automation in A to remove any content with the deadline set till June 2023 (so we are only using what is for use " current content")

This is a one-time automation; we do not need it to run multiple times. How can I set up the script for each scenario?

 

Thank you in advance for your support and guidance,

 

Best regards,


Catherine

 

Best answer by OliCoral

Hi Catherine,

 

If you need to clean your base, (B or A), one time only, i suggest you to do it manually :

  1. filter on your deadline column to get record older than June 2023
  2. then select those record and delete it.

 

If you need an automation to keep your base up to date, you can chose scheduled trigger then execute a  script like :

 

let table = base.getTable('id_of_your_table')
  let queryResult = await table.selectRecordsAsync({
    fields: ["id_of_your_field_deadline"],
    sorts: []
  })
 
for(let record of queryResult.records) {
  if(record.getCellValue("id_of_your_field_deadline") >=  Date('2023-06-01')){
     await table.deleteRecordAsync(record.id)
  }
}
 
BR
View original
Did this topic help you find an answer to your question?

2 replies

OliCoral
Forum|alt.badge.img+6
  • New Participant
  • 3 replies
  • Answer
  • August 26, 2024

Hi Catherine,

 

If you need to clean your base, (B or A), one time only, i suggest you to do it manually :

  1. filter on your deadline column to get record older than June 2023
  2. then select those record and delete it.

 

If you need an automation to keep your base up to date, you can chose scheduled trigger then execute a  script like :

 

let table = base.getTable('id_of_your_table')
  let queryResult = await table.selectRecordsAsync({
    fields: ["id_of_your_field_deadline"],
    sorts: []
  })
 
for(let record of queryResult.records) {
  if(record.getCellValue("id_of_your_field_deadline") >=  Date('2023-06-01')){
     await table.deleteRecordAsync(record.id)
  }
}
 
BR

Forum|alt.badge.img+4
  • Author
  • New Participant
  • 1 reply
  • August 26, 2024
OliCoral wrote:

Hi Catherine,

 

If you need to clean your base, (B or A), one time only, i suggest you to do it manually :

  1. filter on your deadline column to get record older than June 2023
  2. then select those record and delete it.

 

If you need an automation to keep your base up to date, you can chose scheduled trigger then execute a  script like :

 

let table = base.getTable('id_of_your_table')
  let queryResult = await table.selectRecordsAsync({
    fields: ["id_of_your_field_deadline"],
    sorts: []
  })
 
for(let record of queryResult.records) {
  if(record.getCellValue("id_of_your_field_deadline") >=  Date('2023-06-01')){
     await table.deleteRecordAsync(record.id)
  }
}
 
BR

Thanks. I ended up doing it manually, as suggested as this was a one-time thing, but good to now how to run a similar script if needed.

 

Many thanks


Catherine


Reply