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 / Submit Form triggers g...
Power Apps
Unanswered

Submit Form triggers gallery default code?

(0) ShareShare
ReportReport
Posted on by 71

Hey all, 

 

So, I have a simple app.  It has a gallery that a user can navigate through, along with a connected form that displays and allows edits to data.   

 

I have a save button that allows a user to save any changes made on the form.  When a user clicks the save button, and I do a SubmitForm(), the code in the Default function in my gallery is executed.  Why on earth would this code in my gallery be executing when I do a SubmitForm? And does anybody know how to stop this from triggering?

 

Thanks!

Troy

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @TeeroyLyon 

    When you state the "code in your default function" - are you really stating the formula that you have in your Items property of the Gallery?

    If so, this is very common if your formula contains any functions that are "data altering or shaping".  So, using functions like AddColumn, GroupBy, etc. or even function for sorting will cause the gallery to have to re-evaluate its data when you alter the base datasource of the gallery.

     

    There are a couple of options.

    1) Make use of the Default property of the Gallery to reassign the last selected record in the Gallery.  This is usually a bit complicated if you have a fairly extensive Items property on the gallery as the record you specify in the Default must match EXACTLY the record that would be found in the Items property.

     

    2) Isolate the datasource into a snapshot variable for the Item property.  This has the negative that your Gallery data will not be current as it will be based on the snapshot variable.

     

    Either one will work, but which one you do is more dependent on your app design and needs.

     

    Incidentally, this effect ONLY occurs if you have a data altering formula in the Items property.  If you have a simple formula in items, this effect will not happen.

     

    I hope this is helpful for you.

  • TeeroyLyon Profile Picture
    71 on at

    Hey Randy,

     

    First, thanks for the detailed response.   Actually, the Items property in my Gallery has a series of if statements based on filtering options a user can select.  It's a radio button control that allows them to filter the gallery (for example "All items assigned to me").  So based on the filter a user selects, the Items function will filter the gallery appropriately.  The problem this presents is that when the gallery is filtered, the first item in the gallery is not selected after the filter is applied.   So to get around this, I've basically copied the filtering code in the Items function to the Default function in the gallery, but add the First function to each filter to select the first item in the gallery after it's filtered.   This is the only method I've found that seems to work in this scenerio.   The problem with this is that when a user selects an item in the gallery, makes changes and selects Save, the Default function on the gallery is executed...selecting the first item in the gallery (but I need it to stay on the item the user had selected)

     

    Hope this novel makes sense!

    Thanks again

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

    @TeeroyLyon 

    Yes, so in general, you should have no If statements in your Items property and your Default property should be determining the exact record from the same table that is available to the Items property.  Otherwise they will not match and you will see the type of issues you have.  You might be getting a little confused on the Default property of the gallery.  Essentially, if nothing is there or the formula in that property returns a record that does not match, then the Gallery will always automatically select the first record.  This is where most people get annoyed by the fact that the Default is empty, the have scrolled down the gallery to say record 40 and then edit that in the form and save and then the Gallery jumps back to the first one.  That is what is normally seen without the Default working (or not defined).

     

    What is the Items property formula now?  I can take a look at it to see if there is something that is going to cause the problems you have, or if it can be simplified to get rid of the condition you are having.

  • TeeroyLyon Profile Picture
    71 on at

    Thanks for this response Randy.   I have to have an if statement in my Items property as it's the only way I can apply a new filter based on the radio button a user has selected.  So if they select "Items assigned to Me", I have to filter the gallery based on that selection...or if they select "Items past due" I have to filter items based on that selection.  Unless there is another way to achieve this? 

     

    As an update to this, I remove all the code from my Default function, and for some reason, it is all now working (when it was not before I added the Default code).  I'm not exactly sure what changed.  But all seems to be working as expected now? 

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 June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 325 Most Valuable Professional

#2
11manish Profile Picture

11manish 165

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 88 Super User 2026 Season 1

Last 30 days Overall leaderboard