Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Model Driven App Error: Copy of a Record with patch function fails for lookup fields

(0) ShareShare
ReportReport
Posted on by 81
Following some basic Model-Driven app tutorials I am trying to make a command on the main grid command bar to duplicate selected records.  There seems to be an issue when trying to use the patch function to duplicate the lookup field values.  It give the error "The type of this argument 'Lookup Field Name' does not match the expected type 'DataEntity'. Found Type 'Error'.  Has anyone run into this error? Does anyone know how to copy the values of lookup fields?
  • Verified answer
    CE-16101943-0 Profile Picture
    CE-16101943-0 81 on at
    Model Driven App Error: Copy of a Record with patch function fails for lookup fields
    So I actually found the issue after some repeated trial and error.  The problem was that for the LookUp columns the related tables have to be detected within the power fx function.  Simply meaning that the tables appear as an option.  The easiest way to tell if the table has been detected is to right a simple LookUp function for the command.  If the table appears as an option for the lookup then there won't be any errors when trying to update a lookup column in a record.  If you don't see the table then what you need to do is go to that table you are trying to lookup in the model driven app open the edit command bar for that table, add a new command and publish it.  The new command does not need to do anything, and you can remove it after, but this forces the model driven app to detect the table when building a command for other tables.  This is definitely feels like a work around to a bug, but it works.
  • CU21100624-0 Profile Picture
    CU21100624-0 15 on at
    Model Driven App Error: Copy of a Record with patch function fails for lookup fields

    Hello,

    I recently added a 'Copy' button to the main grid in my model-driven app, and here’s how I made it work:

    To ensure the button only appears when an item is selected, I used this condition:

    !IsEmpty(Self.Selected.AllItems)

     

    Here’s the code I used to copy the selected record, including the lookup field LK_Suppliers:

    IfError(
        Patch(
            tblProducts, // Data source
            Defaults(tblProducts), // Creates a new record
            {
                LK_Suppliers: Self.Selected.Item.LK_Suppliers,
                ProductLabel: Self.Selected.Item.ProductLabel,
                ProductTitle: "(copy) " & Self.Selected.Item.ProductTitle, // Adds "(copy)" to the title
                ProductQuality: Self.Selected.Item.ProductQuality,
                ProductGsm: Self.Selected.Item.ProductGsm,
                IsRound: Self.Selected.Item.IsRound,
                ProductLength: Self.Selected.Item.ProductLength,
                ProductWidth: Self.Selected.Item.ProductWidth,
                ProductDiameter: Self.Selected.Item.ProductDiameter,
                ProductHeight: Self.Selected.Item.ProductHeight,
                ProductImage: Self.Selected.Item.ProductImage
                // Add other fields if needed
            }
        ),
        Notify("Error: Could not copy the product.", NotificationType.Error),
        Notify("Product copied successfully!", NotificationType.Success)
    )
     

    Now, when I select a record and click the button, it creates a duplicate of the entry with the specified fields.

    Note - I encountered the same issue initially, but it unexpectedly resolved on its own.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,580

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,909

Leaderboard