I have a parent child data setup, similar to Project and Tasks. When I delete a task, I want to sum the remaining hours on a given project’s task.
I have gotten this to work, but only sometimes. Seems there is a race condition where the calculate function is still counting the task that was just deleted.
It’s my understand database operations can only be forced to run in order if the next database operation is depending/requires values on the previous one. However, in my case, this is not possible.
Is there a way to guarantee that my recalculate step only runs after the delete has full completed?
Create a custom event that has the re-calculate action. “Schedule” the event after the delete action. You’ll need to trial and error the timing for the schedule delay.
Use a database trigger (backend workflow) for the Task data type with a condition: only when Task Before Change is not empty and Task After Change is empty (implying the record was deleted). And then add the action to re-calculate within this trigger event. You’ll probably need to reference “Task Before Change” to access the Project.
The database trigger is likely going to be more reliable. And, if you have multiple places where a task deletion can happen, then this will react to all of those, giving you less to manage.
on database change thing deleted run the backend workflow to calc it
I wouldn’t calc it on the page since the calc needs to happen with several triggers
create, update, delete - and I prefer to do the calc in only 1 place and then just reference the same workflow
I’d hold the calc in a custom event in the backend and then either use an api or database to trigger it