Help

Re: Delete via script - query and filter not working.

147 0
cancel
Showing results for 
Search instead for 
Did you mean: 
noob
4 - Data Explorer
4 - Data Explorer

TIA for any assistance.

I have table1 (vuln) and table2 (archive).  I have an automation that when the record is created a UUID is created in the vuln table.  Then, when the status field of a record in vuln is changed form "new" to "closed" it creates a copy of that record in the archive table. 

What I need is another script that does the opposite.  When the status field of a record in vuln is changed from "closed" to anything else (basically re-opened) it needs to find the record in archive based on the UUID field and delete the copy of that record from the archive table.  I have the trigger setup, but I can't get the script to return the record. 

It returns the query, but the filter does not seem to work.  

This would be easy if I could just do a view, but I can't.  I need to do a weekly purge of the data in the vuln table, but leave the data in the archive data. Hence the data copy.

Here is what i am using for testing:

const archive = base.getTable("Archive");
const inputConfig = input.config();
const vuuid = inputConfig['uuid'];

let archiveQueryResults = await archive.selectRecordsAsync({fields: ['uuid']});

let recordsToDelete = archiveQueryResults.records.filter(
    record => record.getCellValue('uuid') == 'vuuid'
);

console.log(archiveQueryResults)
console.log(recordsToDelete)

2024-11-19_14-24-42.png

4 Replies 4
EddieROLM
5 - Automation Enthusiast
5 - Automation Enthusiast

Hey noob,

Could you try removing the single quotes around 'vuuid'? that might be causing it to compare to the string literal instead of the value.

Hey @noob

Why don't you trigger the automation immediately and do you want to run it weekly? 

You could delete immediately the record for which there automation was triggered, the code for this simpler and available in documents from Airtable.

Thanks
Dimitris 

That would be easier, but ...  I need the user to be able to re-open or unwork an item for 7 days.

I refactored accordingly and now it works!!  Thank you.

2024-11-20_11-13-09.png