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 / Issue with getting the...
Power Apps
Answered

Issue with getting the last ID generated in sharepoint list after previous record is deleted.

(0) ShareShare
ReportReport
Posted on by 140

Hi all, 

 

I am using the Patch default command to create a new record in SharePoint List. I then set a global variable to obtain the last Sharepoint list generated unique ID:

 

 i.e. Set(RecordIDNo, Last( SharePointList ).ID); which works every time to get the ID record.

 

However, recently i went to delete the old records and create a new record using the same method and it returned the previous item ID instead of the new record ID. I went to create another record after that and then it return the right ID subsequently. 

 

May I know how can this error be resolved ? Thank you . 

Categories:
  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Boon-1 
    First(Sort(splist, ID, Descending)).ID will get the last ID in a SharePoint list even if the list exceeds 2000 items. (the maximum allowed in File>Settings>Advanced Settings> Data row limit).   Last() and Max() are not delegatable and will be incorrect if the list exceeds the maximum number of Items.  

    Last(FirstN(Sort(SPlist,ID,Descending),2)).ID will get the second to last ID. 
    FYI: ID numbers are not reused in a SharePoint list even if an Item is removed.

  • Boon-1 Profile Picture
    140 on at

    Hi @Drrickryp ,

     

    It works. But it comes with a delegation warning. ( Delegation warning. The highlighted part of this formula might not work correctly on large data sets. The "First" operation is not supported by this connector). Any alternatives in case my records get too large?

     

     

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Since the Sort() will work no matter how large the list, and since you are sorting on ID and returning ID, and  since FirstN() will never exceed 2000 (actually it is only 2 records), the delegation warning will never have an effect and can be ignored. 

  • PHemingway610 Profile Picture
    130 on at

    @Drrickryp You rock.  Thank you.  You saved me from wasting too much time on this today!

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    smiling.gif

     

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 223

Last 30 days Overall leaderboard