This is a little tricky to do in Appsheet. Since I recently had to implement something similar I will try to lay out a method based on your initial post.
The overall process is this: you have an “Automation” that runs when order status is changed to “Closed”. This automation will then update the inventory table when users change the status to “Closed”.
1. Add an Inventory Updated column to “Open Orders”
You will need to add a column to the “Open Orders” table that the system can use to track which closed orders have been processed. A “Yes/No” column called “Inventory Updated” would do the trick. This column should default to “No”, and since you don’t want users messing with it you should uncheck the “Show” attribute. It would also be good to set an expression on the “Editable” attribute under update behavior to “false”. Note that this is not the same as unchecking “Editable”… the documentation expands on how to set “Editable if” expressions. This will allow the system to update the field, but not users.
2. Add a Behavior to “Update Inventory for Closed Orders”
You will also need to add a “Behavior” for your inventory table. Lets call it “Update Inventory for Closed Orders”. For the “Do This” field choose “Data: set the values of some columns of this row”. You then choose your quantity column in the “Set these column” field. For the value you need to craft an expression that will decrement the quantity by the picked quantity. This would look something like this:
[Quantity] - INDEX(SELECT(Open Orders[Quantity], AND([Item ID] = [_THISROW].[Item ID], [Order Status] = “Closed”, [Inventory Updated] = “No”)), 1)
Note that the “INDEX” function is necessary because the “SELECT” function returns a list and you cannot do arithmetic with a list. INDEX just returns the first item in the result.
3. Create an “Automation” to do the work
You then create an Automation on the Open Orders table that triggers on [Order Status] = “Closed”. To do this you go to the Automations section and add an Event that triggers on updates to the “Open Orders” table. The condition will be an expression that looks something like this:
AND([Order Status] = “Closed”, [Inventory Updated] = “No”)
You then create a “Bot” that uses the newly created event. You will then create a process for the bot with two steps:
The first step will “Run Action on Rows” of your inventory table. The referenced rows field should be an expression that selects the appropriate inventory record. This would look something like this:
SELECT(Inventory[Item ID], [Item ID] = [_THISROW].[Item ID])
The “Referenced Action” should be the behavior you created above: “Update Inventory for Closed Orders”
Then create a second step in the process. This process step will “Set Row Values”. It should set [Inventory Updated] = “Yes”.
After that you should have the behavior you desire. I wrote this from memory so there may be mistakes in here. If you spot any mistakes or any of the steps are unclear, you can DM me and I’ll update this post.