I am new to powerFx and I am trying to clone a parent record and its associated child record in a model driven app. I have found the pattern below but I am getting errors with it.
I am trying to write powerfx code to clone product and product items – I have 2 tables. Parent table Product and child table ProductItem. ProductId is the foreign key in the ProductItem table from Product. I want the ProductId of the new record to be linked with every ProductItem record that was cloned from the parent product and I want to insert these new records in the ProductItem table
The power fx code is as follows
With(
{
clonedrecord: Patch(
Product,
Defaults(Product),
{
Name: Self.Selected.Item.Name & " - Clone"
}
)
},
// Clone Child records
ForAll(
Self.Selected.Item.ProductItems,
Patch(
ProductItems,
Defaults(ProductItems),
{
ProductId: clonedrecord.ProductId,
ProductItemId: ThisRecord.ProductItemId
}
)
)
);
The For statement is resulting in reported errors that I cannot use a non-record type in this context . The first part of closing the parent works as expected. The clone part is giving errors. Does this code need to filter the records in ProductItem
So that only records linked to the original owner are re inserted as being linked to the new ProductId
Any help is gratefully appreciated
Thanks
Ois
I want to clone the parent and the child recorda linked to the parent using powerfx in a model driven powerapp
Oisín ÓGlacáin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.