Update Parent after Child is modified

Hi guys,
please how to update PARENT record when CHILD is created/updated/removed?
It looks like easy task but I spent already 2 days on this and I’m going crazy. Tried n community hints, but still no functional solution. Please, can someone help me?

regards Marek

It would be helpful to know what kind of update you are wanting to make to the Parent. If your Child changes are being made in the app from a form, there is a good chance you can update the parent there as well.

Since you have implied that you want the Parent change AFTER the child row is Saved then I’ll continue with that assumption.

I’ll assume you have the “IsPartOf” flag turned on for the Parent/Child relationship.

To make changes to the parent fields when a Child row changes you’ll need to create a Workflow that then calls an Action, call it Action 1.

In Action1 make it of type “execute an Action on a set of rows” and transitions to the Parent row so you can access the parent fields to make updates. The Reference Rows expression is simply [Parent ID].

Create a second Action, Action2, of type “set the values of some columns in this row” and assign it as the Reference Action in Action1.

Update Action2 to select the columns you want to update.

If you are wanting to update with information from the child row that just changed, you will need someway to identify that row so you can implement a SELECT() statement in the parent fields being updated to choose the value from that child.

I hope I have made it clear and it helps.

1 Like

@marcotvic Please check the sample app “EventAction” from www.appsheet com/portfolio/531778. That sample app is updating the parent record when child record is added or updated.

2 Likes

@Aleksi I think I just ran into the issue that maybe @marcotvic was initially referring to. I’ll call it Direct edit of a child record such as when selecting it from a Parent Detail view (not Edit mode).

I implemented your suggested process shown in the EventAction app. But I have realized that while I can now update the Parent based on Direct Edit/Add of a child, The Parent DOES NOT update when Edit/Add a child while in Edit mode of the Parent. My understanding this is because EventsActions on Form Save do not fire for children when changed as part of the Parent Edit.

So…leveraging your experience, is there currently in the UI a way to achieve both Child Edit use cases AND update Parent field with result of child Edit? Use cases are:

  1. Change/Add Child as part of Parent Edit.
  2. Direct Change/Add of Child - not initialed by Parent Edit

I am certain there are Workflow/Action solutions for updates AFTER the UI save, but that is less than ideal!

1 Like

The easiest solution is always an action button that user trigger from parent record. Is that a solution in your case?

1 Like

I almost get it. Only the last part about SELECT I don’t understand. I want the key form the last added child record added to a column in the parent record. If I use the reference column, I get a list of keys of all the child records. How and where do I select the last one, or the one just made by current user.
Hope you can help me out.

Try:

ANY(ORDERBY([Related Childs], [_ROWNUMBER], TRUE))

replacing Related Childs with the name of the column with the “list of keys of all the child records”.

3 Likes

Wow Steve, that is a quick response. And a good one. It is working nice, now i can get forward wih some nice actions. Thank you very much.

Bert

2 Likes

I am trying to implement the same…
I have two tables - Customer Details (Parent) and Quotation Details (Child).
Parent can have multiple child records and Child ‘IsPartOf’ Parent.

I want to update the customer total cost as I add/update rows in Quotation Details. I have replicated exactly the same event action as @Aleksi mentioned. However, in my app the following scenario gives the desired results (will use the same terms as you have):

  1. Update in Direct Edit - WORKS
  2. Update in Parent Edit mode - WORKS (I have to save the parent for the force update to happen)
  3. Update in Child edit mode - WORKS
  4. Update when child is added - WORKS
  5. Update single row in Child quick edit mode - DOES NOT WORK
  6. Update multiple rows in Child quick edit mode - DOES NOT WORK
  7. Update when row or rows deleted in Child table - DOES NOT WORK

How do I force the event action to update customer total cost from quick edits/delete happening in child table?

First, Quick Edits are different and probably not ideal for a Parent/Child relationship where an update to the other is required - at least at this time. Quick Edits are sent immediately for update in the datasource and you have no way to tap into that action to perform actions of your own.

If you like the idea of Quick Edits and wish to keep them, the only way to make the Parent re-calculate is by using a Workflow. However, as you are likely editing Child records in other ways, this Workflow may get triggered at times when not necessary. I am not sure how you can distinguish between when an Edit is made on the Form versus when it is by a Quick Edit. I suppose you could add a column to track when the edit is made by the form.

For Deletes, I assume you are referring to a Delete when you have accessed the Child row directly - i.e. not through the Parent. In that case, the simplest way is to create a Workflow for Deletes only that forces re-calculation of the Parent. Again, you may see unneeded Workflow triggers when you have deleted “normally” - navigated through Parent to child row to delete.

If for some reason you need to see the Parent update quicker than a Workflow provides, with some effort, you can create a custom grouped delete action to perform the update and then deletion of the child. We can discuss further if needed.

2 Likes