Recently I had a scenario where I needed to create a new record in a Dataverse table using a canvas app, but I then needed to have that record assigned to another user so that they as a basic user would see it. In this blog post weāll take a look at how to assign a Dataverse record to someone else using the Patch() function in a canvas app.
Getting the record to update the owner of
So first, weāll look at the basics. Iām going to start by attempting to retrieve a record in my app which Iāll update the owner of with the Patch() function in a moment. In my case Iām going to try to get hold of a record in my Accounts table which has the account name āMicrosoft Corporationā.
To do this weāll use a LookUp() function in our app. Iām simply going to use a text label to display a property from my retrieved record or āobjectā.
Iāll start by adding a text label to the screen and then Iāll use the following formula in the Text property.
LookUp(Accounts, 'Account Name' = "Microsoft Corporation").'Account Name'
Now youāll see that I have the Name field of my retrieved record displayed on the screen.

Using this logic, weāve been able to get the record with the following formulaā¦
LookUp(Accounts, 'Account Name' = "Microsoft Corporation")
And we can then access the fields within the record using dot notation after the closing bracket at the end and referencing fields to get to the information we need. In this case of using a text label we wouldnāt be able to just reference the record without using dot notation to get into the fields as the text label wants a string value back but we would be able to use just the lookup without dot notation to get to a field when we need a record for something like a Patch(). Weāll use this in a moment when we use the Patch() function to do the owner update.
Getting a user record
So the next part weāll take a look at, and see if we can do, is getting hold of the user record in Dataverse that we need to patch against the parent record which in my case is an Account. Weāll patch this to the Owner column which is a lookup against the User table.
Iām going to see if I can get hold of the user record for someone in my organsiation called John Doe. Weāll lookup Johnās user record using his email address.
To get hold of Johnās user record weāll try a similar thing and display a property from the record using a text label. This time in the text property weāll use the following formula to display Johnās name.
LookUp(Users, 'Primary Email' = "johndoe@lewisdoes.dev").'Full Name'
Now I have Johnās name displaying in the second text label Iāve added to my screen.

Now I know I can get hold of the record I need to update the owner of, and the record for the user that I want to patch against my parent record (Account). Letās see if I can patch the record in.
Updating the owner of a record using a canvas app
Now for ease. Iām going to use a simple button in my app, Iām going to set a global variable with the record I want to update as my owner (User record), and Iāll just reference the global variable when I want to do my patch further down in my formula. Iāll also set a global variable for the record I want to patch and reference this in my Patch.
In the OnSelect of my button, Iāll use this formula to update the owner of my account record.
Set(
gblAccountToPatch,
LookUp(
Accounts,
'Account Name' = "Microsoft Corporation"
)
);
Set(
gblUserToSetAsOwner,
LookUp(
Users,
'Primary Email' = "johndoe@lewisdoes.dev"
)
);
Patch(
Accounts,
gblAccountToPatch,
{Owner: gblUserToSetAsOwner}
);
Now if I select my button and check my record after, I can see that John is now the new owner of the record!

Now something to note with patching an owner column is that this is a polymorphic data type which effectively means that the lookup column can be patched with records from more than one table. In the case of patching Owners, the Patch() function already knows that this column can be patched with either a user record or a team record.
In other cases we might have to do some more work sometimes when working with polymorphic data types, which you can read more about here.
Understand record references and polymorphic lookups in canvas apps ā Power Apps | Microsoft Learn