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 / Using variable for gal...
Power Apps
Answered

Using variable for gallery.selected item not updating when datasource changes

(0) ShareShare
ReportReport
Posted on by 24

Hello, I'm struggeling with a problem of the gallery.selected item.

When I select a item in my gallery and then navigate to another screen2, I can show a field (eg "name") of my datasource ("projects") with setting item > gallery.selected. That's fine.

Now I add a form ("updateForm") on screen2 to edit and update the field "name". When I klick the button with OnSelect>Submit(updateForm). The field "name" (wich I placed outside the form on screen2) is directly showing the updated value I just had send from my updateForm. That's still fine and the way I need it.

Now the problem:

When I add a SortByColumns() on my gallery, the gallery.selected does not keep the item (I actually selected by klicking it) when I perform a Update of the datasource on my updateForm on screen2. The selected item of the gallery automatically switches to the first Item of the table (depending on the SortByColumns logic) and does not keep the one I have chosen.

So the value of "name" on screen2 now shows another datasource (because I have set Item to "gallery.selected" which is now anotherone!).

Some postings with the same issue suggested to use a variable instead. So I put a variable on the OnSelect of my Gallery:
Set(SelectedItem,gallery.selected) and replaced this in item on screen2 (now Item is set to SelectedItem instead of gallery.selected).

So when I navigate to screen2, the chosen item is shown correctly with my value "name" of source "projects". Thats fine.

But when I change the value in my updateForm on screen2 now (as before), the value of my field "name" is not show the now updated content as it did before, when I used gallery.selected directly!!! 
Thats my problem: The variable is not showing the updated data in my screen2 now.
I tried with Refresh(projects) on the Submitformbutton, but that doesn't help.

Somehow the gallery.selected is sending updated data directly to screen2 while the variable SelectedItem is not.

Is there any way to handle this?

Otherwise I can only choose between keeping Item on galery.selected and not using SortbyColumns in my gallery or accepting screen2 is not showing my updated data (which is a problem for me...)
Thanks alot in advance for help. I found a couple of simmilar postings on this issue by others without a final solution (or I didn't get it..)
Regards

 

Categories:
  • v-qiaqi@microsoft.com Profile Picture
    Microsoft Employee on at

    Hi @PaSk,

    Let's simplify your need, you want the UpdateForm display the updated item after submission, right?

     

    If so, I think you could do something comparison to populate the UpdateForm with the Gallery.Selected or latest item.

    Follow the 3 steps as below:

    1). Set the OnSelect property of the Gallery as below:

    Set(SelectedItem,BrowseGallery1.Selected)

    2). Set the OnSuccess property of the form as below:

    Set(SelectedItem,EditForm1.LastSubmit)

    3). Set the Item property of the form as below:

    SelectedItem

     

    Let's suppose that we open this app right now, select an item from the Gallery and it will navigate you to the UpdateForm where displays the SelectedItem as Gallery.Selected. Once you edit something within and submit it successfully, the OnSuccess property of the form will update the SelectedItem with Form.LastSubmit, which is what you want to achieve.

  • PaSk Profile Picture
    24 on at

    Hello Qi, thanks for your reply. I don't really understand the logic of "Form.LastSubmit" in context of a variable defining the selected item - but it works for me.

    But how can I achieve the same effect (updating the SelectedItem variable) when not using a form to update data but using a single edit field with OnSelect > Patch('Datasource',ThisItem,{Field:Value})? This doesn't have a OnSuccess Field.

    Regards PaSk

  • Verified answer
    v-qiaqi@microsoft.com Profile Picture
    Microsoft Employee on at

    Hi @PaSk,

    LastSubmit – The last successfully submitted record, including any server generated fields.

    • This property applies only to the Edit form control.
    • If the data source automatically generates or calculates any fields, such as an ID field with a unique number, the LastSubmit property will have this new value after SubmitForm successfully runs.
    • The value of this property is available in the OnSuccess formula.

    OnSuccess – Actions to perform when a data operation has been successful.

    • This property applies only to the Edit form control.

     

    If you do not have an edit form but a single edit field with a button OnSelect property, you could only get the last modified item by using the following formula:

    Last(Sort(List,Modified,Ascending))

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 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 271

#3
Mohsin Ali Profile Picture

Mohsin Ali 239

Last 30 days Overall leaderboard