Scenario: Imagine you run an online store and use Power Apps to manage orders and product details. You want a function that:
Creates a new order with a "New" status.
Adds corresponding order details for each item in the order.
Breaking it Down with Power Fx:
Here's the magic behind the scenes:
Explanation:
Patching the Orders Table:
Patch(Orders, Defaults(Orders), {OrderStatus: "New"}): This line updates the OrderStatus field to "New" in the Orders table.
Patch updates a record, and Defaults(Orders) creates a new record with default values for all fields. Here, we only modify OrderStatus.
Orders Table
Looping Through Order Details:
Inside the loop, another Patch function creates a new record in the OrderDetails table for each item in the order.
We set the Order field to the current OrderID (likely obtained from the newly created order in step 1), along with Quantity and ProductID from the NewOrderDetails table.
Tables with Sample Data: