cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BenjixLeGauloix
Frequent Visitor

Patch a collection item from gallery selection

Hi,

 

I recently found out a strange behavior using the Patch function on the item within a collection.

Basically, I am using a gallery to display items of this collection.

When I select an item on the gallery (linked to the collection) and try to patch it I get two different behavior using these two pieces of code:

 

Patch(col, gallery.Selected, {column1: "updated text"}

 

and

 

Patch(col, LookUp(col, ID = gallery.Selected.ID), {column1: "updated text"})

 

 

With the first code, the no change happens on the gallery. The collection is not modified.

Whereas the second code gets the gallery to be updated.

 

Could somebody explain what is happening? Is gallery.Selected some sort of a copied record? Isn't it supposed to be a reference (in the C pointer fashion)?

Many thanks for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User III
Super User III

Hi @BenjixLeGauloix,

I always use the second, but like this (and it always works)

Patch(
   col, 
   {ID:gallery.Selected.ID}, 
   {column1: "updated text"}
)

I believe the issue is that this one directly identifies the record (you are telling Power Apps exactly which record ID to Patch), whereas Gallery.Selected is simply a copy of that record that happens to be selected from the data source and Power Apps has to work out what it matches. I noticed your reference to C - I had to "unlearn" a lot of VBA principles when I started on PowerFX.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

2 REPLIES 2
WarrenBelz
Super User III
Super User III

Hi @BenjixLeGauloix,

I always use the second, but like this (and it always works)

Patch(
   col, 
   {ID:gallery.Selected.ID}, 
   {column1: "updated text"}
)

I believe the issue is that this one directly identifies the record (you are telling Power Apps exactly which record ID to Patch), whereas Gallery.Selected is simply a copy of that record that happens to be selected from the data source and Power Apps has to work out what it matches. I noticed your reference to C - I had to "unlearn" a lot of VBA principles when I started on PowerFX.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

BenjixLeGauloix
Frequent Visitor

Hi @WarrenBelz ,

Many thanks for your helpful wisdom, as always 🙂

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,186)