web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Select last record in ...
Power Apps
Unanswered

Select last record in gallery and perform action

(0) ShareShare
ReportReport
Posted on by 443

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...

 

Select(Last(ItemDetailGalleryNew.Selected.Button_NewSave))

 

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...

Categories:
I have the same question (0)
  • lumberjacklurch Profile Picture
    443 on at

    Got one more error:

     

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

  • lumberjacklurch Profile Picture
    443 on at

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

  • v-yutliu-msft Profile Picture
    on at

    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

  • lumberjacklurch Profile Picture
    443 on at

    @v-yutliu-msft

    Here's a screenshot of the customized form.

     

    SalesReqSS1.png

  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    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? 
  • lumberjacklurch Profile Picture
    443 on at

    @yashag2255

    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),

     

    SubmitForm(SalesRequestFormNew);

     

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

     

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

     

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

  • lumberjacklurch Profile Picture
    443 on at

    @yashag2255

    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.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 793 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 333 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard