I want to update an order’s Total each time I add or update a new Order_Items entry.
I can’t find a way to do it using a bot that detects the Add/Update event on the Order_Items table. Perhaps there is another way of doing this? Any help is appreciated.
Thanks Austin! It seems a virtual column is the way to go for most cases. However, I was trying to update a real column in the Orders table so I could then use this column from within Sheets to create a report of all orders.
For sure. Here is a quick walkthrough of how we set up our work order automation and template. Hope this helps! Let me know if you have any other questions!
So, I always think it’s best to try and make people “work” for the answers because it strengthens the knowledge and the community as a whole - rather than just issue a straight answer.
My response was mainly helping you identify the steps and solutions you need to take. (Always the very first thing you should do - then move on to simplifying the process)
So, to start with, how do you plan to select all the RELEVANT Order Items?
First of all, you will need to SELECT() a “unique” value that appears in both Orders and Order_Items, which I would assume is [Order No]
Now, seeing as you aren’t utilising a virtual column, you may run into an issue where the total isn’t updated as frequently as you want (or at all in some cases!)
You can do one of two things here (or both!)
Option 1.
Use a virtual column for the above expression, called [TOTAL COST] (or something similar, whatever you want). This will update “automatically”.
Add a standard column with an expression value of :
[TOTAL COST]
Option 2 (PREFERRED).
Create an action/behaviour/automation that automatically updates the parent row whenever an edit on the child rows are made.
(I just create a “dummy column” and set an action to set a random value or something similar but that is for a later date). One problem at a time.
@Ryan_Mortimer thanks for the suggestions. I do appreciate the answers you provided.
Regarding Option 1:
I tried using the virtual and standard columns approach and it technically works, but it doesn’t update when a child record is added. Only when the Orders record is updated it updates the standard column with the value of the virtual column.
Option 2 is what I was trying to achieve from the beginning.
Where I think I am stuck is trying to understand the limitations of the automation features provided by Appsheet in terms of detecting an event in a child record and then updating it’s parent record. It seems there is no straight forward way to do this, or maybe I’m not understanding how to use it correctly.
Added a process Update_Parent for the table Order_Items with a step Update_Order_Total to run the action on a set of rows of the referenced table Orders using this filter
So the bot is being triggered by the Child_Change event on the Order_Itemsdata. When the event is detected the bot calls the Update_Order_Total process that runs the Update Total action on the row that matches the filter criteria that selects the parent record in Orders. The Update Total action simply copies the virtual column value to the standard column.
The key to make it work is step 4, having a data action that Runs an action on a set of rows. This allows the action to be performed on a different data set, in this case Orders, even though the event was detected on the Order_Items data set.
Here is how I achieve this in my solutions for my customers, brace yourself it will be a longer read.
In the parent table, create a normal column (not a virtual one!) called [ActionTrigger]
Navigate to Behaviours > Actions
Create a new action called “AutoUpdate1” where it sets the value of [ActionTrigger] to “X”
Create a new action called “AutoUpdate2” where it sets the value of [ActionTrigger] to “XX”
Create a new action Called “AutoUpdateMain” with “Do This” set to Execute a sequence of actions.
Set the Actions to the following 3, in this order
Action 1 = AutoUpdate1
Action 2 = AutoUpdate2
Action 1 = AutoUpdate1
Start a new automation with
Event:
Data Change
Adds & Updates
Table: “Order_Items”,
Process:
Run a data action,
Run Action on rows
Referenced table: orders
Referenced rows: [ORDER ID] = [_THISROW].[ORDER ID]
Referenced Action: “Autoupdate”
@jrullan this is a great example of multiple ways to achieve the same or similar result.
It’s not up to you to decide which is most appropriate for the application/scenario and which utilises best practices for the application/scenario.
Also, taking the time to optimise each and every step is very important too - (ie. using a Filter or Select expression rather than a reverse reference)