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 / LastSubmit for Patch
Power Apps
Unanswered

LastSubmit for Patch

(0) ShareShare
ReportReport
Posted on by 17

Hi!

 

I had a problem submitting a form with SubmitForm(), so the solution I found was submitting the form with Patch(). However, I used LastSubmit() to the the ID if the form submitted, but since I'm using Patch() now, the LastSubmit() function isnt working. do you have any suggestions of other functions I could use to replace LastSubmit() for Patch()?

Categories:
I have the same question (0)
  • ANB Profile Picture
    7,223 Super User 2025 Season 2 on at

    Hi @amanda-ami , You can use Last function to get the last record from data source. Last(DataSource)

     

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

    I hope this helps.

    Please click Accept as solution ✅ if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs up.👍

    Thanks,
    ANB


  • timl Profile Picture
    36,383 Super User 2025 Season 2 on at

    @amanda-ami 

    The return value from Patch returns the details of the record that was patched, including server-generated ID values. You can store this in a variable and use it to retrieve the ID value.

    Set(varLastSubmit, 
     Patch(YourDataSource, .....)
    )

    Once you do this, you can reference varLastSubmit.ID to retrieve the last submitted ID value.

     

    Note that calling Last returns the last record that was added to the data source, and this might not be the record that was added by the user if another user added a record at the same time.

  • v-qiaqi@microsoft.com Profile Picture
    on at

    Hi @amanda-ami,

    To get the last submit id, you could use the following formula:

    First(Sort(list,Modified,SortOrder.Descending)).ID
  • timl Profile Picture
    36,383 Super User 2025 Season 2 on at

    Whilst "First/Sort Descending" will work, this approach still suffers from the issue that if another user were to create a record at the same time, it may not return the required record. The most reliable way to retrieve the last submitted record is to reference the return value from Patch.

    Set(varLastSubmit, 
     Patch(YourDataSource, .....)
    )
  • Cel87 Profile Picture
    171 on at
    Any solutions on this one. I'm having a similar issue.
    I have a Patch function
    Save Button --OnSelect =
     
    Set(
        varNewUniqueID,
        If(
            IsBlank(Last('SLO - Affiliated Club Addresses')),
            1,  // Use 1 if there are no records in the list
            Last('SLO - Affiliated Club Addresses').UniqueID + 1
        )
    );
     
    If(
        UpdateClubForm.Mode = FormMode.New,
        Patch(
            'SLO - Affiliated Club Addresses',
            Defaults('SLO - Affiliated Club Addresses'),
            {
                Title: DataCardValue44.Text,
                Activity: ComboActivity.Selected.Title,
                Multi_Use_Facility: DataCardValue54.Selected,
                'Street Address': DataCardValue47.Text,
                Suburb: ComboSuburb.Selected.Title,
                Postcode: ComboPostcode.Selected.Title,
                LGA: DataCardValue50.Text,
                State: DataCardValue51.Text,
                UniqueID: varNewUniqueID
            }
        ),
        SubmitForm(UpdateClubForm);
       );
     
    ViewForm(UpdateClubForm);

    However, when I save it returns the last record I looked at in my gallery. Any ideas.

     
    My OnSuccess = 
    ResetForm(UpdateClubForm);
    ViewForm(UpdateClubForm);

    In my Gallery - OnSelect =
    Select(Parent);
    ViewForm(UpdateClubForm);
    Navigate(UpdateClubForm);

    any and every assistance would be helpful
  • Suggested answer
    Talha_Dar Profile Picture
    870 Super User 2024 Season 1 on at
     
    Try using the following to get the next unique id
     
    Set(
        varNewUniqueID,
        If(
            IsBlank(First('SLO - Affiliated Club Addresses')),
            1,  // Use 1 if there are no records in the list
            First(Sort('SLO - Affiliated Club Addresses',UniqueID,SortOrder.Descending)).UniqueID + 1
        )
    );
     
    If(
        UpdateClubForm.Mode = FormMode.New,
        Patch(
            'SLO - Affiliated Club Addresses',
            Defaults('SLO - Affiliated Club Addresses'),
            {
                Title: DataCardValue44.Text,
                Activity: ComboActivity.Selected.Title,
                Multi_Use_Facility: DataCardValue54.Selected,
                'Street Address': DataCardValue47.Text,
                Suburb: ComboSuburb.Selected.Title,
                Postcode: ComboPostcode.Selected.Title,
                LGA: DataCardValue50.Text,
                State: DataCardValue51.Text,
                UniqueID: varNewUniqueID
            }
        ),
        SubmitForm(UpdateClubForm);
    );
     
    ViewForm(UpdateClubForm);

    This will get the correct new unique id for the new record.
     

    I hope this information is helpful!

    If my post resolved your issue, please click "Accept as Solution" so others can easily find it too. This will also mark the item as closed. If you found the content useful in other ways, a "Thumbs Up" would be greatly appreciated.

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 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard