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

Patch reverts to first item in Gallery

Hi all,

 

I have got this strange behaviour. I have 2 Sharepoint lists and want to update both lists when a button is clicked. The first time it works as expected, but then the Gallery reverts to the first item, not the selecte one. I want the gallery to stay on the selected item. As I said: when I patch the second sharepoint list, my gallery reverts to the first item in the gallery. If I remove the second patch it stays on the correct selected item. 

 

What am I doing wrong?

 

Capture.PNG

I hope someone can help me out. Listened all videos from @ShaneYoung, who saved me a lot of times. But this one is really interesting. 

 

Regards, Kea

1 ACCEPTED SOLUTION

Accepted Solutions

This is normal behaviour. The data source is changing so the gallery is refreshing changing the selected item to the first in the gallery not the one you previously selected. 

 

What I do in this case is set the OnSelect in the gallery to store the item. Set(varRecord, ThisItem) then I use varRecord in place of Gallery.Selected. That way nothing changes. 🙂 

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training

View solution in original post

9 REPLIES 9
sopatte
Microsoft
Microsoft

I'm having a hard time understanding your scenario and the issue. I'm not sure what it is you're seeing when you say "the Gallery reverts to the first item, not the selected one". Is the selection changing? Are the contents of the gallery changing? What is in your gallery (Items property)? Maybe boil this down to a simpler case that illustrates the problem clearly.

This is normal behaviour. The data source is changing so the gallery is refreshing changing the selected item to the first in the gallery not the one you previously selected. 

 

What I do in this case is set the OnSelect in the gallery to store the item. Set(varRecord, ThisItem) then I use varRecord in place of Gallery.Selected. That way nothing changes. 🙂 

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training
Kea
Frequent Visitor

 Thanks Shane!!! Keep up the good work.

Anonymous
Not applicable

I do not think this is by design. Patching an item that happens to be selected in a gallery should not affect which item is selected. I also noticed that this is somewhat inconsistent - sometimes it changes and sometimes it does not (depending on the patched data). I suspect this is a bug that has to do with modifying the item in place vs. creating a new item internally when patching.

Thanks. Your solution work like a charm @Shanescows  🙂

Simmzee
New Member

Unfortunately, setting the OnSelect in the gallery to store the item. Set(varRecord, ThisItem) then putting varRecord in place of Gallery.Selected in the Patch formula didn't work for me. It writes back to SharePoint without any issues, the only issue is it reverts back to the top of the gallery after the update. Any other suggestions would be much appreciated?

Gallery below;

OnSelect.PNG

 

Save Button on Form below;

Patch.PNG

Hi Shane, thank you for your suggestion but this is not longer working. I am not sure if its because of an update.

@v-antal , I had the same problem right at the same time as you so I concur something definitely changed. I came up with what is probably the dumbest workaround, but at least it will work until smarter minds figure this out. Sorry, I am a novice at this and probably don't provide the best "technical instructions." I noticed that if the gallery was filtered (the filter must result in one selection) prior to being selected that patches inside the gallery do not reset. Likely because when the gallery is queried or whatever it looks and sees your filter showing the one item. So I set a variable in the gallery item selection button to filter the gallery by entering text via the variable into the search text input (that I already had for the user to search the gallery) which filters the gallery and then navigates to the next screen. When I navigate back to the gallery I have that screen's OnVisible setting the variable back to "" so that all items appear. That is probably the worst explanation ever, but it worked for me. Good luck! Definitely looking for a better solution if anyone has it. 

365-Assist
Power Participant
Power Participant

Shane's solution is great. However just be careful that your Gallery Items property doesn't have code (e.g. Filters and Sorts) that refresh the gallery data. 

If this is the case One workaround is to use variable to store the record selected before the refresh occurs.

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (3,997)