Showing results for 
Search instead for 
Did you mean: 

Select last record in gallery and perform action

I have a customized form that has a gallery, and in each row/record has a button that saves the item/row to a collection.  The collection is patched after the above form is submitted.  There is a chance that a user will not click on the button in the gallery before submitting the form.  If that happens, the information that should go along with the form is not captured.  I want to mitigate this possibility by selecting the last record's button before the form is submitted.  I tried the below...




It didn't work though.  Got the following errors:


The function 'Last' has some invalid arguments.

The function 'Select' has some invalid arguments.

UpdateContext cannot be used on rules belonging to global controls


Really don't understand that last one...


Re: Select last record in gallery and perform action

Got one more error:


Invalid argument type (Control).  Expecting a Table value instead

Re: Select last record in gallery and perform action

I need to clarify, the button is not actually a button.  It is an icon.  The disk icon, to be specific.

Community Support Team
Community Support Team

Re: Select last record in gallery and perform action

Hi @lumberjacklurch ,

Do you have a gallery and an edit form and set the form's item to gallery.selected?

Could you describe more clearly about your app or show me screen shoots about it?

I'm a little confuse about your description.


Best regards,

Community Support Team _ Phoebe Liu

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.

Re: Select last record in gallery and perform action


Here's a screenshot of the customized form.



Dual Super User
Dual Super User

Re: Select last record in gallery and perform action

Hi @lumberjacklurch 


Can you please share the formula that you have used on the save icon?
Also, do you want to update the collection even if the form is not submitted? 

Re: Select last record in gallery and perform action


Here's the code for the Save icon:


Update(col_ItemDetailNew, ThisItem, {ItemName: NewItemVal.Text, ItemDescription: NewDescripVal.Text, ItemQuantity: Value(NewQuantityVal.Text)});

Collect(col_ItemDetailNew, {ItemName: "", ItemDescription: "", ItemQuantity: 0})


Here's the relevant code from the OnSave property:


Set(var_ColRowCount, CountRows(col_ItemDetailNew));

Set(var_GalRowCount, CountRows(ItemDetailGalleryNew.AllItems));


If(var_ColRowCount=1 || !IsBlank(Last(ItemDetailGalleryNew.AllItems).ItemName), Notify("Cannot submit request. Items not saved. Click disk icon to save items, then click Save.", NotificationType.Error),




Set(var_NewLastSubmitID, SalesRequestFormNew.LastSubmit.ID);
Set(var_NewLastSubmitTitle, SalesRequestFormNew.LastSubmit.DepartmentName & "-" & var_NewLastSubmitID);


RemoveIf(col_ItemDetailNew, IsBlank(ItemName) && IsBlank(ItemDescription) && ItemQuantity=0);


Patch('Sales Item List', Defaults('Sales Item List'), {'Item Name': ItemName, 'Item Description': ItemDescription, 'Item Quantity': ItemQuantity, 'Request ID': var_NewLastSubmitID, Title: var_NewLastSubmitTitle}))

Re: Select last record in gallery and perform action


I think I should give a bit more detail on this.  

I have a list where people will be submitting sales requests via a customized form.  The customized form has two parts: an edit form and a gallery.  The edit form is where departmental and contact information is put in, and the gallery is where the list of items for sale are put in.  When the form is submitted, a new sales request item is created in the request list and the list/collection of items is patched to an item list that is linked to the request via the request's ID.  Now, when a user is inputing the list of items for sale (in the gallery), they have to click the Save icon so that their entry/item is saved to a collection (ItemDetailNew).  The collection is when is patched.  I am trying to make the form account for any possibilities.  One of those possibilities is a user may fill out the form, enter their first item, click the save icon, enter a second item, but not click the save icon again.  So if they click Save, only their first item is patched to the items list for their request.  I need to know if there is a way to see if the second (or third, or fourth) line in the gallery is populate, but is not in the collection.  Then to not allow the app to go any further until the save icon is clicked.

I hope this clears up my objective.  Let me know if I'm unclear on any parts, or if you need more info.

Helpful resources


Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!


Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020


Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (6,065)