I am digging into PowerFx in Command Bar within Model Driven Apps doing a clone of parent record (Quote) and child records (Quote Lines):
I am using a With statement to capture the newly created Quote guid to reference in the Quote LInes patch statement:
With({
quote_recid:
Patch(Quotes,
Defaults(Quotes),
{
Name: "Copy of" & Self.Selected.Item.Name,
'Potential Customer (_customerid_value)': Self.Selected.Item.'Potential Customer (msdyn_account)',
'Potential Customer (msdyn_account)': Self.Selected.Item.'Potential Customer (msdyn_account)',
'Primary Contact': Self.Selected.Item.'Primary Contact',
'Price List': Self.Selected.Item.'Price List',
Currency: Self.Selected.Item.Currency,
'Work Order Type': Self.Selected.Item.'Work Order Type',
'Payment Terms': Self.Selected.Item.'Payment Terms'
}
)
},
//Clone Child Records
Patch('Quote Lines',
ForAll(Self.Selected.Item.'Quote Lines' As quoteproducts,
Patch(
Defaults('Quote Lines'),
{
Quote: quote_recid,
'Quote Product': quoteproducts.'Quote Product',
Quantity: quoteproducts.Quantity,
'Price Per Unit': quoteproducts.'Price Per Unit',
Unit: quoteproducts.Unit,
'Product type': quoteproducts.'Product type',
'Sequence Number': quoteproducts.'Sequence Number'
}
)
)
);
Notify("Quote Copy of " & Self.Selected.Item.Name & " and its lines have been cloned. Please open the records and update the necessary fields.");
);
Within PowerFX, it does not show any errors so I am not sure where it is erroring out. I have a case open with Microsoft but waiting to hear back.
My copy of the Quote gets created and my notification inside Sales Hub also works.
Something is wrong with my //Clone Child Records.
Any peer review here of my code would be appreciated or if there is another approach I could take.
Thank you!