cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
msmith
Level 8

Display Next SharePoint ID

Is there a way to auto populate a number field with the next item id of a SharePoint list? So if I have items with the id's of 1,2,4,9 - 10 will be the next one. It should be the highest number of all the items because there will be times when items will be deleted. 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Display Next SharePoint ID

Hi @msmith,

I use First(Sort(datasource,ID,Descending)).ID+1. This allows you to avoid problems with large SharePoint lists as Last() and Max() are not delegatable and your list may grow beyond 2000 items. However, be aware that SharePoint automatically assigns a consecutive primary key as part of the list’s metadata and this value is exposed in PowerApps and can be referenced in formula. If this answers your question, please mark the discussion as solved. 

View solution in original post

4 REPLIES 4
Super User
Super User

Re: Display Next SharePoint ID

Hi @msmith,

I use First(Sort(datasource,ID,Descending)).ID+1. This allows you to avoid problems with large SharePoint lists as Last() and Max() are not delegatable and your list may grow beyond 2000 items. However, be aware that SharePoint automatically assigns a consecutive primary key as part of the list’s metadata and this value is exposed in PowerApps and can be referenced in formula. If this answers your question, please mark the discussion as solved. 

View solution in original post

EdHansberry
Level: Powered On

Re: Display Next SharePoint ID


@Drrickryp wrote:

Hi @msmith,

I use First(Sort(datasource,ID,Descending)).ID+1. This allows you to avoid problems with large SharePoint lists as Last() and Max() are not delegatable and your list may grow beyond 2000 items. However, be aware that SharePoint automatically assigns a consecutive primary key as part of the list’s metadata and this value is exposed in PowerApps and can be referenced in formula. If this answers your question, please mark the discussion as solved. 


According to this page, First isn't delegateable either. But just so I understand, your solution works because Sort is delegatable and so it doesn't matter how many records are in the Sharepoint list, the sort will always put the last record on top (due to descending sort order) and you can grab that via First()?

Super User
Super User

Re: Display Next SharePoint ID

yep
Highlighted
DaveNicholls
Level: Powered On

Re: Display Next SharePoint ID

I have a similar situation to this, however if the last record in the was deleted prior to the new record being patched/added, then the number is incorrect, as sharepoint will have already used the deleted ID number. Any ideas on how to get around this?

Helpful resources

Announcements
thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

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

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (4,810)