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

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

Top Solution Authors
Top Kudoed Authors
Users online (57,805)