Clone Command Bar Button in Model Driven App: Order & OrderDetails


This article is a quick overview of the process of making an ORDER & ORDERDETAIL  Clone button in one Action. When the user clicks on the Clone button, the system will automatically create a copy of the order with all the related orderdetail (line items). This in the context of Model-Driven Power Apps using Dataverse and Power-Fx low-code tools.

Prototype ERD for this Order Entry System
Visit https://online.visual-paradigm.com/ if you want to use this tool


 Now, Let's make a custom command bar button

Start Here: make.powerapps.com

Make a new command bar, command button, on the command bar. Then, on the Main Form using Power Fx formula below, we will build a Clone function that not only Clones the Parent Order Record but also the related Child OrderDetails (line items). It also sets the OrderDate to the current date. 

Model-Driven Apps: Modern Command Bar Customization 
Credit to Scott Durow for the original version. Below is modified version.
(Link:  https://youtu.be/Jq2GLgNEcp0?si=K4xodRYmI_fvjNVd)

Here is the Modified Power Fx Formula with minor tweaks.




The ORDER Clone button in Action.




















Next, After We Cloned the Order, We can now see the Cloned Order including the cloned line items.
Notice that the OrderDate was not cloned and instead set to current date (when clone was created)



GRAB A COPY OF THE ORDER CLONE POWER FX HERE:

Note: If anyone finds a solution for the sub-grid column totals in model-driven apps using no-code/low-code Power Fx formula, please let me know. 

With(
    {
        purchaseOrder: Patch(
            Orders,
            Defaults(Orders),
            {Name: "Copy of "& Self.Selected.Item.Name,
            Customer:Self.Selected.Item.Customer,
            //OrderDate:Self.Selected.Item.OrderDate}
            OrderDate:Today()}
        )
    },
    // Clone child record ie line items for this order
    Patch(OrderDetails,
        ForAll(Self.Selected.Item.OrderDetails As LineItem,
            Patch(
                Defaults(OrderDetails),
                {
                    Order: purchaseOrder,
                    Name: LineItem.Name,
                    Product: LineItem.Product,
                    Qty: LineItem.Qty
                }
            )
        )
    );
    Navigate(purchaseOrder);
    Notify("Order Successfully Copied! Now edit the copied order as needed.");
    
);


Comments

Popular posts from this blog

Model-Driven Apps: Modern Command Bar Customization

Knowledge shared is power squared!