web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Model Driven App Error...
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?
Categories:
I have the same question (0)
  • CU21100624-0 Profile Picture
    15 on at

    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.

  • Verified answer
    CE-16101943-0 Profile Picture
    81 on at
    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 88

#2
WarrenBelz Profile Picture

WarrenBelz 85 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 45

Last 30 days Overall leaderboard