Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

onselect in gallery

(1) ShareShare
ReportReport
Posted on by

We have a problem with OnSelect of a gallery.  This app was built a long time ago and I have to work with it.

 

Basically we have two galleries, one is to display data, and another is on another screen with the ability to update/delete/add the data. 
These two galleries are using two different collections for the data.

In the second screen gallery to update the data, there is a patch() function in OnSelect.  Basically if there are change to the entries in this gallery, patch works with its collection to update or add new entries.  

 

What seems to be happening is created a function in the first gallery to duplicate data.  I add the data to its collection and it seems fine.  However, when I click to move to the second gallery, that is for update/delete/add, its Patch function inside OnSelect seems to execute and adds a bunch or repetitions of the duplicate line I added in the first gallery.  

so if this is confusing.  Even I'm confused.

 

Basically the second screen for update/delete/add has Clear and ClearCollect to recollect for the gallery and the data is fine, but when this second screen and gallery loads the Patch in OnSelect seems to execute and adds a bunch of repetitions in its collection?  Like if I added one entry, there is that entry, and another 4 more repetitions of that entry.  Which if we submit the form then these repetition entries and entered the sharepoint library.  that sucks.

 

I even put a test collection in the OnSelect of gallery like ClearCollect(whatisgoingon, ThisItem) and I can see that on load of this screen and gallery whatever is in OnSelect executes.  Why?  I didn't select any entries!?
I do not understand why it executes AND then adds multiple repetition of the entry or entries I added.  I understand why they put the patch there in OnSelect, because they want to patch "ThisItem", but why does it run on load?

 

Here is an idea of the code
second screen on visible has:
Clear()
ClearCollect(secondcollecction,Filter(table, ID = whatever))

and in the second gallery's OnSelect this is the patch:

Patch(
 secondcollection,
 ThisItem,
 {
 Title: txtSAFProject.Text & "_" & cboSAFType.Selected.Value & "_" & cboSAFFY.Selected.Value,//txtSAFTitle.Text,
 SAFType: cboSAFType.Selected,
 FY: cboSAFFY.Selected,
 ProjectPhase: cboSAFProjectPhase.Selected,
 ProjectID: Value(txtSAFProjectID.Text),
	 Project: txtSAFProject.Text,
 SAFAmount: Value(txtSAFAmount.Text)
 }
);

 

Categories:
  • gstlouis Profile Picture
    on at
    Re: onselect in gallery

    Thanks for the note.  I've looked pretty hard for strange things that could trigger this onselect gallery.  In the OnSelect I've put in Notify("what is going on") and every time I load this screen it triggers.  So it is more like something is triggering this gallery's on select on load and I do not understand why.  There is nothing out of the ordinary onVisible of this screen.  I just do not know why it triggers.

  • jrletner Profile Picture
    715 Super User 2025 Season 1 on at
    Re: onselect in gallery

    @gstlouis I would suggest using the code search feature in PowerApps to try and find some other location within your application that is calling that gallery's onselect property. It could be hiding anywhere.

     

    Search for:   Select(theGalleryName) or even a Select(Parent) somewhere else in your gallery. Could be hidden in a hover property too.

     

  • jrletner Profile Picture
    715 Super User 2025 Season 1 on at
    Re: onselect in gallery

    @gstlouis I'm sure you're looking into this but:

    • Check if there are any other triggers (such as OnVisible or OnStart) that might be causing the Patch function to execute during gallery load

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,668 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,004 Most Valuable Professional

Leaderboard