web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Help with collection
Power Apps
Unanswered

Help with collection

(0) ShareShare
ReportReport
Posted on by 820

Hi

I have a gallery and a hidden Button inside. On all gallery controls on property "On Change" i have Select(Button) formula. On the Button on property "On Select" I have my formula to add changes to collection so whenever user make any change on the gallery items the button is pressed and it is added to collection. That work fine. But here is the issue i do not understand.

I have created another 2 buttons. One of them adds new blank line into gallery( i patch a record into data source) and whenever the new line is added all existing gallery items are recorded into collection and i don't understand why.

Same situation is with button copy where i copy First gallery item into data source and within copying it also makes other list items recorded into collection.

What i am doing wrong and how to solve it? 

Categories:
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @jja 

    This is because your OnChange action is occurring when you are adding the blank line.

    I would suggest abandoning using a collection for this and get rid of the buttons and simply utilize the Gallery items.  The gallery already is a table of records, this is all you need in order to perform any actions later on perhaps on a button that submits it all to the datasource.

     

    I hope this is helpful for you.

  • julijazas Profile Picture
    820 on at

    @RandyHayes 

    I got your point of view but theoretically for me it seem this on change should trigger only the gallery items that i make changes. Adding new lines i make change only to new line not to other records?

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @jja 

    This would be true in a development and programming world, but not in PowerApps!

    When you alter the underlying table of your Gallery, the gallery will re-evaluate its controls.  During that process it will cause actions to occur that you would not expect.

     

    So, the best choice is to avoid trying to program it and instead work with it as the table that it already is.  There is no need for all the extra work to be done by you in designing your app to maintain an additional table.

     

    However, the above said...when you are basing a gallery off of a collection table, you will want to just make sure that your controls are getting their default values from values in your collection...and that does mean making sure that the controls are reflected properly in the collection.

    The only reason you need the collection though for the gallery is to be able to add and/or remove a row.  That is because the gallery needs a table.  The collection will serve as that and is flexible for add/remove.  However, beyond that, when you go to work with the data in the gallery, just treat it like any other table (the table is exposed with the GalleryName.AllItems property).

    From that table you have access to everything about the record in the gallery - including the controls in that row and the values of those controls.

  • julijazas Profile Picture
    820 on at

    @RandyHayes 

    The other reason that i use collection is that if user loads gallery with existing data, makes changes i can easily track which records user changed and what needs to be patched back to data source with one button click? I can also show him some icon which gallery lines are changed. The question is if i work only woth gallery wothout collection how do i tell to patch only those lines/records that are changed or added new with new line?

  • julijazas Profile Picture
    820 on at

    I have found a solution how to avoid triggering on change property when adding new line, copying or deleting to gallery. What i did i created 2 hidden labels. In one label I concatenated all text from ThisItem properties on another i concatenated values from all controls in galeries in exact order and in this case created like ID's. Then on my all controls in gallery in On change property i say if(label1.text=label2.text,false,Select(btnClick). In this case it will not collect anything what is unneccesary and it catches exactly if i change something in gallery

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @jja 

    So it is still extra work to deal with the OnChange actions.

    In this case you have already created essentially what you need.

    The concept is this - take your formulas for the two labels and put them all together in a toggle or checkbox Default property.

    Example Default property:  !(With(ThisItem, column1 & column2 & column3) = control1.Text & control2.Text & control3.Text)

    This will turn the checkbox or toggle to true whenever there is a change.

    Then in your final formula, 

    Patch(yourDataSource,
     ForAll(Filter(yourGallery.AllItems, yourCheckOrToggle.Value),
     {column1: control1.Text, 
     column2: control2.Text,
     column3: control3.Text
     }
     )
    )

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 382 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 329

#3
WarrenBelz Profile Picture

WarrenBelz 187 Most Valuable Professional

Last 30 days Overall leaderboard