cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kirillperian
Frequent Visitor

Filtering gallery based on last submitted item in form

Hi,

I have a gallery and the form on the same screen. The form's Items property is Gallery.Selected.

The form's default mode is View and then it changes the DisplayMode depending on whether I need to add or edit it.

What I want is for the form to stay on the record that I just created after I submitted it.

I have a Save button with:

 

 

OnSelect = SubmitForm(FormName); ViewForm(FormName)

 

 

...but the form switches from that record to the record that was last selected in the gallery, even though the OnSuccess properties of the form are as follows:

 

 

OnSuccess = FormName.LastSubmit.Key

 

 

 I am thinking that since the form in its DisplayView.Mode is tied to Gallery.Selected, it probably overrides the OnSuccess criteria of the form.

Any suggestions on how to keep the DisplayView.Mode on the record that was just submitted? Maybe Default property of the Gallery can be somehow adjusted?

1 ACCEPTED SOLUTION

Accepted Solutions
v-yutliu-msft
Community Support
Community Support

Hi @kirillperian ,

Do you mean that:
1)this form could be used to edit, create and view?

2)if you select one item in the gallery, the form will be used to edit an existing record 

3)if you click the add button, the form will be used to create a new item and display this new item in view mode after you submit this form?

If so, I've made a similar test for your reference:

1)the gallery's Items:

fruit11111
//my data source name

gallery's OnSelect:

EditForm(Form1);Set(mode,"edit")

2)insert an add button

set its OnSelect:

NewForm(Form1)

3)insert an edit form, set its data source:

fruit11111

set its Item:

If(mode="edit",Gallery1.Selected,Form1.LastSubmit)

insert a submit button, set its OnSelect:

SubmitForm(Form1);ViewForm(Form1);Set(mode,"view")

 

//then if you click the gallery, the form will change its mode to edit and display the selected item.

If you click the add button, the form will change its mode to new. If you submit the form, the form's mode will change to view and display the new item.

 

811.PNG

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
eka24
Super User
Super User

Either; 

On the form item change it to FormName.LastSubmit

 

Or

Filter the Gallery to show the first item on top;

Sort(Datasource,Key, Descending)

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Hi, @eka24 !

Thank you for your response!

My gallery has the correct order of sorting (and I don't want to change that) and if I change my form's Item property to LastSubmit, it will disconnect from the gallery and then if users are clicking on the gallery items, the form won't reflect the selection.

@kirillperian in that case, take two context variables - one is on gallery.selected and another one is on save. use both to switch your form modes.

varNewForm - true  and varViewForm - false on Save button...similarly 

varNewForm - false and varViewForm - true on gallery.selected

If the Gallery is well sorted, it means new items saved don't reflect immediately in the Gallery?

 

In that case change the Onsuccess to;

Set(Mylast,FormName.LastSubmit)

 

Then insert a button the can switch between the Gallery and the last Submit. Onselect of the button;

UpdateContext ({ChangeGal:!ChangeGal})

 

Then in the items of the form, change it to:

If(ChangeGal,MyLast, Gallery1.Selected)

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

v-yutliu-msft
Community Support
Community Support

Hi @kirillperian ,

Do you mean that:
1)this form could be used to edit, create and view?

2)if you select one item in the gallery, the form will be used to edit an existing record 

3)if you click the add button, the form will be used to create a new item and display this new item in view mode after you submit this form?

If so, I've made a similar test for your reference:

1)the gallery's Items:

fruit11111
//my data source name

gallery's OnSelect:

EditForm(Form1);Set(mode,"edit")

2)insert an add button

set its OnSelect:

NewForm(Form1)

3)insert an edit form, set its data source:

fruit11111

set its Item:

If(mode="edit",Gallery1.Selected,Form1.LastSubmit)

insert a submit button, set its OnSelect:

SubmitForm(Form1);ViewForm(Form1);Set(mode,"view")

 

//then if you click the gallery, the form will change its mode to edit and display the selected item.

If you click the add button, the form will change its mode to new. If you submit the form, the form's mode will change to view and display the new item.

 

811.PNG

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,845)