Skip to main content

Notifications

Power Apps - Microsoft Dataverse
Answered

Gallery selection is lost when SubmitForm

(0) ShareShare
ReportReport
Posted on by 10

Hello

 

The Gallery selection is changed when I edit a record and SubmitForm.

 

Please refer to this link

 

https://powerusers.microsoft.com/t5/Building-Power-Apps/Bug-Gallery-with-calculated-values-will-lose-Selected-index-when/m-p/161150#M54252

 

When will this issue be fixed.

 

I tried the following

 

https://powerapps.microsoft.com/de-de/blog/decouplingbrowsegalleryfromforms/

 

It was working before. When the powerapps got updated this is not working as expected. I cannot see the record data in my Display Screen

 

Please suggest how to fix the same

 

Thanks And With Regards

Partha

  • LS-03012056-0 Profile Picture
    LS-03012056-0 2 on at
    Gallery selection is lost when SubmitForm
    Fcosta,
     
    your workaround works for me perfectly, thank you so much!
  • Suggested answer
    FCosta Profile Picture
    FCosta 2 on at
    Gallery selection is lost when SubmitForm
    @PhilD, we're in 2024 and the same issue persists: the solution provided here (or anywhere else I could find on the Internet) does not work properly if you use the Search() function on the Gallery's Items definition.
     
    I was able to devise a workaround for that - caveat emptor, it works, but it is not super elegant:
    1. Adjust MyGallery.Items so there is a Row number in each record:
      With({Items: Search(... your original gallery items here ...)},
          ForAll(Sequence(CountRows(Items)),
              With({ThisItem: Index(Items, Value)},
                  {ID: ThisItem.ID, Name: ThisItem.Name, ... any other attributes you want to retrieve..., Row: Value}
              )
          )
      )
    2. On MyGallery.OnSelect, put: UpdateContext({SelectedGalleryItem: MyGallery.Selected})
    3. Create a Timer control, and configure it as follows:
      • AutoStart: SelectedGalleryItem.Row <> MyGallery.Selected.Row
      • Duration: 1
      • OnTimerEnd: If(Self.AutoStart, Select(MyGallery, SelectedGalleryItem.Row))
    That's it! At least in my use case, I could not see any important side-effects.
     
    Solution explanation: if you manually select an item in the Gallery, the timer will trigger, but the guard condition in OnTimerEnd prevents it from doing anything (and even if it did, it would have no effect in the Gallery). However, if you change the underlying data listed in the Gallery, the timer also triggers, but the guard condition will evaluate to true, forcing the "proper" item to be re-selected immediately after the Gallery contents are refreshed.
  • PhilD Profile Picture
    PhilD 1,009 on at
    Re: Gallery selection is lost when SubmitForm

    🙄

  • PhilD Profile Picture
    PhilD 1,009 on at
    Re: Gallery selection is lost when SubmitForm

    Tested this just now, the problem has to do with a gallery that has the Search() function as part of its items property. 

     

    This worked fine with a Sort(), Filter() in the items property but the moment I added the Search() part it looses its selection when refreshed no matter what convention is used to define the default item (I tried dozens of variations). It doesn't make a difference where the search function is nested, or if alone or in combination with other functions, as soon as it is introduced, it will not work.

     

    Bottom line, this doesn't work as it is supposed to and its been like this for years. Almost every gallery requires a search function and having the selection randomly jump around is completely jarring and disorienting to the user and is not acceptable. Incredible that a developer is not given consistent and reliable way to control the selection in PowerApps...

  • PhilD Profile Picture
    PhilD 1,009 on at
    Re: Gallery selection is lost when SubmitForm

    This straight-up does not work! Used precisely the same thing and will not work.

  • Verified answer
    Re: Gallery selection is lost when SubmitForm

    Hi @kbpartha24 ,

    Do you mean that after you submit an edit form, the gallery's selected item will change?

    Actually, the theory is the same as the issue that you posted.

    Since the gallery's Items is AddColumns(..), after you submit a record, the gallery's selected item will be refreshed.

    To deal with this problem, you just need to save the selected item as a variable. Set your edit form and display form's Item to this variable.

    Even if the gallery's selected item will be refreshed after you submit a record, it will not refresh your variable.

    I've made a similar test for your reference:

    1)set the gallery's OnSelect:

    Set(CurrentSelectItem,ThisItem)

    set the gallery's Default:

    CurrentSelectItem

    2)set the edit form's Item:

    LookUp(datasource,ID=CurrentSelectItem.ID)

    set the display form's Item:

     

    LookUp(datasource,ID=CurrentSelectItem.ID)

     

    //please replace with your data source name, your unique field, I use ID as an example

     

    Then your display form's item will not change after you submit form.

     

     

    Best regards,

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,636

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,942

Leaderboard

Featured topics