Help

Script help: Delete record script triggers automation watching for updated fields?

Topic Labels: Automations
360 5
cancel
Showing results for 
Search instead for 
Did you mean: 
oreocereus
7 - App Architect
7 - App Architect

I have a script set up to delete records when they enter a view. 

I fiound the script on this forum, it's: 

 

let table = base.getTable("Field & Nursery");
let inputConfig = input.config();
let recordId = inputConfig['recordId']
await table.deleteRecordAsync(recordId);

 

However, when this script runs, it triggers another automation. Update (I misspoke about how the automation works - amended here) The deletion is handled by:
- If the record appears to need deleting, the status changes to a pending deletion status
- A formula looks for records of the pending deletion status that are over x days old (depends on the kind of record) and outputs a "Delete" string (otherwise this field outputs nothing).
-The automation looks for records that match "Delete" in the formula field.



The script seems to behave in a way that the fields that are being watched "look" updated.

However, because the script is deleting the record, this second automation fails. 

I assume there is something I don't understand about this script? Does anyone have any guidance?

5 Replies 5

Hm yeah that's a weird one, just tested it and managed to replicate this.  As a workaround, I'd suggest creating a view that excludes any records that you want to delete and to make the automation that's watching for record updates use that specific view, does that make sense?

That's strange. I suppose we considering the same table in automation 1 & 2.
Delete operation couldn't run the update trigger, unless you have a kind of self-linking
My assumption - filter in your view has common fields with update watcher. Thus, when such field updated, and the result is record entering a view, it runs automation 2 and automation 1 simultaneously, but #1 has higher priority, so it runs the script and in the same time it trying to run #2, but cannot.


Ahh, yeah that makes sense!  Just tested it and it worked exactly like you said; once I removed the update watcher on the shared field it worked as expected

Nah, none of the same fields being watched! I actually misremembered the trigger, so I'll update the original post:
the deletion is handled by:
- If the record appears to need deleting, the status changes to a pending deletion status
- A formula looks for records of the pending deletion status that are over x days old (depends on the kind of record) and outputs a "Delete" string (otherwise this field outputs nothing).

The automation looks for records that match "Delete" in the formula field.

I think @TheTimeSavingCo  has the right idea from the start.

If you make your "Update Automation" look at a view that does not include any "Delete" values, it won't run when it finally gets deleted from the other view.

Your "Script Automation" can still run from your view that only contains "Delete" values over x days old.

You can still have a master view but run these automations from these other specific views. I'd also suggest locking the views so things don't get accidentally mixed up in the future 🙂