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

secondImage

Demo Extravaganza is Back!

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

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (68,779)