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

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Wrong (but same value)...
Power Apps
Unanswered

Wrong (but same value) patching to a lookup column in Dataverse table

(0) ShareShare
ReportReport
Posted on by 660 Moderator

When I try to patch to a look-up column incorrect value is being patched. Also, the value that is being patched is the same every time.

 

I have one table called Product Table (Plural: Product Tables) and another table called Patch Test (Plural: Patch Tests).

 

Product Table Columns:

BhargavPatel_0-1693023689049.png

 

Patch Test Columns:

BhargavPatel_1-1693023765925.png

Items in the Product Table are added to the collection colSelected if the checkbox is checked. 

 

BhargavPatel_3-1693024580419.png

 

Data in colSelected

BhargavPatel_4-1693024692532.png

 

OnSelect of the "Patch" button I want to patch the items in colSelected to the Product column (Type: Lookup, Related Table: Product Table) in the Patch Test table.

 

OnSelected property of the Patch button:

 

 

 

 

ForAll(
 ShowColumns(
 colSelected,
 "awc_productcode"
 ),
 Patch(
 'Patch Tests',
 Defaults('Patch Tests'),
 {
 Product: LookUp(
 'Product Tables',
 'Product Code' = ThisRecord.awc_productcode
 )
 }
 )
)

 

 

 

 


But same record keeps getting patched regardless of what is in the colSelected collection.

BhargavPatel_5-1693024974051.png

So, I added two more columns to the Patch Test table: Item Name and Item Code both single-line text columns. Update the OnSelect property of the Patch button to:

 

 

 

 

 

ForAll(
 ShowColumns(
 colSelected,
 "awc_productcode","awc_productname"
 ),
 Patch(
 'Patch Tests',
 Defaults('Patch Tests'),
 {
 Product: LookUp(
 'Product Tables',
 'Product Code' = ThisRecord.awc_productcode
 ),
 'Item Name': ThisRecord.awc_productname,
 'Item Code': ThisRecord.awc_productcode
 }
 )
)

 

 

 

 

 

Correct values for the Item Name and the Item Code columns were patched, but the value for the lookup column, Product, was still

wrong.

BhargavPatel_6-1693025616880.png

 

I cannot figure out what am I doing wrong, and hoping someone here can point me in the right direction.

I have the same question (0)
  • Verified answer
    BhargavPatel Profile Picture
    660 Moderator on at
    Re: Wrong (but same value) patching to a lookup column in Dataverse table

    So essentially the same record was getting patched in the LookUp column because when I used "ThisRecord" inside LookUp( ) function it was referencing the source table that was also inside the LookUp( ) function. In my case, it referenced the Patch Table table instead of the colSelected collection. This caused the LookUp( ) function to return the entire table, and while patching, the first record in the table was being patched every time.
    I was able to solve this by utilizing the With( ) function to set the values of each field as a variable, and then reference that variable inside the LookUp( ) function. 

    ForAll(
     ShowColumns(
     colSelected,
     "awc_productname",
     "awc_productcode",
     "awc_producttableid"
     ),
     With(
     {
     pc: ThisRecord.awc_productcode,
     pn: ThisRecord.awc_productname,
     id: ThisRecord.awc_producttableid
     },
     Patch(
     'Patch Tests',
     Defaults('Patch Tests'),
     {
     'Item Name': pn,
     'Item Code': pc,
     Product: LookUp(
     'Product Tables',
     'Product Table' = id
     )
     }
     )
     )
    )

     

    BhargavPatel_0-1693082166821.png

     

  • Verified answer
    BhargavPatel Profile Picture
    660 Moderator on at
    Re: Wrong (but same value) patching to a lookup column in Dataverse table

    I found another way solution to my original problem by using the As operator. 

    I changed my code to below which is even simpler and successfully patched the correct record to a Look Up type column. 

    ForAll(
     ShowColumns(
     colSelected,
     "awc_productname",
     "awc_productcode",
     "awc_producttableid"
     ) As Cart,
     
     Patch(
     'Patch Tests',
     Defaults('Patch Tests'),
     {
     'Item Name': Cart.awc_productname,
     'Item Code': Cart.awc_productcode,
     Product: LookUp(
     'Product Tables',
     'Product Table' = Cart.awc_producttableid
     )
     }
     )
     )

     

    Here is a blog post that explains more on the subject. 

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
WarrenBelz Profile Picture

WarrenBelz 819 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 308 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 222 Super User 2025 Season 2

Last 30 days Overall leaderboard