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 / Best Practices for sub...
Power Apps
Unanswered

Best Practices for submitting and refreshing data

(0) ShareShare
ReportReport
Posted on by 1,088

Hi I've been building PowerApps for quite a while, but not sure I really know what the best way to submit data and keep my app refreshed.

 

So I'll put this out here and please let me know if I have an misconceptions.

 

For this discussion, I have an app, SharePoint lists for the data, Creating collections at app startup for each SP List, I have multiple Galleries on my main screen and I have a couple other screens for adding new records or editing.

 

So one of the frustrations I often have is after adding a new record or editing, the data in my galleries isn't always updated and also sometimes I lose my sorts and filters.  Also sometimes I can see other records for a second before I transition to my primary screen. or Other weird things

 

Should I be setup like this in this order:

 

New Form

Save Button > ON Select

  1. Data Validation Stuff
  2. Data Calculation Stuff
  3. Set other variables for visibility, required, colors, etc.
  4. Submitform

 

Then for the form, On Success

  1. Additional Patches
  2. ClearCollect (with sorts/filters)
  3. Navigate
  4. Reset Forms

 

Other Questions:

  • What about refresh do I need it?  Do I need ClearCollects and Seperate ClearCollects with Filters/Sorts?  Or just once?
  • For the Galleries is it best to have them tied to the collections or the SP Lists themselves?
  • Should I use on visible on the main form to do any sorting/filtering of the galleries or just use the onselect/onsuccesses?

 

Thanks,

Terry

 

Categories:
  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    Hi @Mattw112IG ,

    Your model sounds very similar to what I do, so I will provide my humble opinion on my methodology. I must also note that I operate on the "abundance of caution principle" in that if unsure, is better to do something not necessary than not to do something necessary. So covering your points

    New form - pretty much what I do.

    OnSuccess - if you are not getting the data you want all the time, add a Refresh(DataSource) before the ClearCollect.

    Your questions

    • Refresh - whenever I do not always get new data, I add a refresh. This is particularly important when you are relying on collections (which I do extensively). The other little "trick" I do with these is that other than the OnStart code, I put a hidden button somewhere with the collection code in the OnSelect and then use Select(ButtonName) whenever I want the collection to trigger - saves a heap of repetitive code.
    • Galleries - depending on what you are using them for. Collections are very much faster to filter when using search boxes and also to scroll down bigger lists. Mine (except very small lists) are almost all collections.
    • Filtering/Sorting - I have always used the Items property of the gallery to do sorting. If a collection, I do this at App OnStart. I am not sure what you mean with the OnSelect as it is already filtered and sorted.

    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.

  • Mattw112b Profile Picture
    1,088 on at

    Hi,

    I have a case where I have a three galleries, all use collections as base.

     

    Selecting an item in the first gallery, filters the items in the second gallery, selecting an item in the second gallery filters the third gallery.

     

    I have a screen, where I can create a new item that goes into gallery 3.

     

    Onsubmit it does a lookup of a number in collection #2 and saves to a variable then it submits the form.

     

    On Success I reset the form. Patch SP#2 (tied to collection #2) with the variable I collected +1, Refresh SharePoint lists.  ClearCollect the Collections. Navigate to the form, but the field is not updated?

     

    What else can I do?

     

    Also, you meantioned "other than the OnStart code, I put a hidden button somewhere with the collection code in the OnSelect and then use Select(ButtonName) whenever I want the collection to trigger - saves a heap of repetitive code."

     

    You say you put a hidden button somewhere - What form? Gallery, screen?

    With the collection code - what does that mean? ClearCollect? Refresh? Other?

    Then use Select - In what on your save button after submitting the form? On Success?

     

    Thanks,

    Terry

  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    Hi @Mattw112IG ,

    The reference to the hidden button (it could be an icon or even a control) was simply to explain that repetition of code can be avoided by using the Select statement which acts the same as actually selecting the selecting the item. So if you have a button somewhere in the App that OnSelect runs a piece of Collect code, you can Select it from anywhere Select(ControlName) and it will run the code. A bit like calling a function in VB if you have done that. It means if you refresh the collection in five different places, you simply Select the control from each to do this.

    Your process looks right as far as Patching, Refreshing and then Collecting and the process above will not improve that. Strangely (maybe not) a basic SubmitForm generally never has issues with refreshing. Although my galleries are based on collections, my forms are always linked directly to the data source and I use SubmitForm whenever I can.

  • Mattw112b Profile Picture
    1,088 on at

    So I tried this.  I created a button on my screen where the gallery that uses the collection is.

    On select it does a ClearCollect on that collection.

     

    Then I tried to call the onselect form my Edit Screen so that the collection was refreshed before I navigated back.

    But there's an error that you can only use the select command on the same screen as the control.

     

    Terry

  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    Thanks @Mattw112IG ,

    Strangely I have never put it on another screen (just hidden it), so you if that is the testing result, it is correct.

    My comment was more of a tip for saving code.

     

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 393 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 278 Most Valuable Professional

Last 30 days Overall leaderboard