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

Notifications

Announcements

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)
  • 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.
  • 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.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
Kalathiya Profile Picture

Kalathiya 421

#2
WarrenBelz Profile Picture

WarrenBelz 365 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 339 Super User 2025 Season 2

Last 30 days Overall leaderboard