How to get 'Deletes_Only' Bot on child record to work when you delete a parent record, and all child records are deleted

weowens1984
Participant III

I have three tables.

Table 1: Work Orders (Parent)

Table 2: Work Order Line Items (Child)

Table 3: Inventory

I currently have two bots working using webhooks.
Adds_Only - Whenever a work order line item is created, it adds the qty to the inventory table.
Deletes_Only - If that line item is deleted, it removes the qty from the inventory table.

Here is my JSON text, the Deletes_Only is the same except it subtracts from Qty Produced instead of adding.

{
โ€œActionโ€: โ€œEditโ€,
โ€œPropertiesโ€: {
โ€œLocaleโ€: โ€œen-USโ€,
โ€œTimezoneโ€: โ€œMountain Standard Timeโ€
},

โ€œRowsโ€: [
<<START:SELECT(Parts[Part ID],[Description]=[_THISROW].[Product/Part])>>
{

โ€œPart IDโ€: โ€œ<<[Part ID]>>โ€,
โ€œQty Producedโ€: โ€œ<<[_THISROW].[Qty]+[Qty Produced]>>โ€

}
<>
]
}

If I delete a Work Order, it deletes all child records in the Work Order Line Items Table, but the โ€˜Deletes_Onlyโ€™ bot does not trigger when this happens.

How do I make a bot that triggers off of the Work Orders table that runs for each child record?

Any help would be much appreciated.

Thanks!

1 11 560
11 REPLIES 11

Automation for when a record is Deleted can be tough. The reason is, that once the record is deleted, the Bot canโ€™t access any of the data from that record. You should set up your automation flow to do the processes that need done when a record is deleted first, then delete the record.

weowens1984
Participant III

So I ended up figuring out a work around for this. I removed the standard delete action from Work Orders. Replaced it with a grouped action.

First it runs Data: Execute an action on a set of rows. This deletes all related Work Order Line Items. This triggers my โ€˜Deletes_Onlyโ€™ Bot for every row deleted.

Second it deletes the work order itself.

I find it very strange that this method triggers the โ€˜Deletes_Onlyโ€™ but when a child record has โ€˜is part ofโ€™ selected and you delete the parent, it does not trigger for the children. Can anyone say if this is intentional or if this is a bug?

Was this ever answered? I have an automation that runs on a child table when its records change, including deletions. The automation runs reliably when rows in that table are deleted directly. However, the automation does not run when a parent row is deleted even those the child rows are also deleted in that scenario.

When a parent row is deleted, nothing in the child row changes, so there's nothing to trigger a bot. You'd need to either use the IsPartOf in the child rows, which will prompt AppSheet to automatically delete the children when the parent is deleted, or setup a bot that responds to the parent deletion and deletes its children.


@Steve wrote:

 IsPartOf in the child rows, which will prompt AppSheet to automatically delete the children when the parent is deleted


IsPartOf is exactly the scenario I'm referencing. I have a table with an IsPartOf column and whose child rows are reliably deleted when the corresponding parent row is deleted. I have an automation that runs when the child table's rows are deleted or otherwise changed. The automation event reliably triggers when the child table's rows are deleted directly, but does not trigger when the child table's rows are deleted as a result of a parent row being deleted.

Ah, I see. I suspect that is the intended behavior. I'll ask internally.

Yes, we explicitly suppress automations when deleting child records as a result of 'IsPartOf'.

It would be possible for us to trigger automations in this case, but it would require adding a new option to control this new behavior. We would need to preserve the current behavior for backward compatibility. 

I suspect we would only make such a change if there was sufficient demand for this new feature in the community.

Thanks for explaining here. That should be incorporated into help documentation about automation so that app creators are aware.

I think this issue is a problem. I have more than 10 tables that triggers on delete. But unfortunately child tables with ref is a part of turned on does not trigger the bot unless we go into child row directly and delete it. Maybe this was the issue that has been investigating by developers for past one week. 

Case ID [4-4107000033574]

RainKun
Participant I

If you are using DB like Postgres, MySQL Server, etc. You can use the triggers function to update, delete, and add in a single click. Learn more here https://www.tutorialspoint.com/postgresql/postgresql_triggers.htm

Top Labels in this Space