SPGetLastItemId does not retrieve proper ID

Nov 23, 2010 at 1:53 PM


I'm using SPRedirectWithID to get the ID of the next item and pass it along to the next page for a parent/child relationship. The problem I'm running into is that if some items with the highest ID's have been deleted prior to adding new ones, when another item is entered, SPGetLastItemId picks the highest old ID value and adds 1 to the counter instead of obtaining the ID that was just entered. So the ID that is found could actually be quite different from what it should be.

Could there be an error in how I've added SPRedirectWithID or is it functioning as intended?




Nov 23, 2010 at 1:58 PM


The only way that would be possible is if the same user is adding items in different browser windows or on different machines. The logic in SPRedirectWithID is to find the current highest ID for the current user on submit and then wait for the highest ID to be higher. It swould actually be pretty hard to sneak a new item in between there. IDs are sequentially assigned by SharePoint and always increase.


Nov 23, 2010 at 2:26 PM

Hi Marc,

Thanks for the quick response! I kindof thought that would be your answer. I suppose there is no way to obtain Sharepoints "nextid" value on a list as a whole?

The list that I'd like to use this on will have multiple users adding to it with maybe a few deletions but that would then put the count out of order. Essentially I was hoping to store the parent ID in the child's entry after the redirect.


Nov 23, 2010 at 2:29 PM

That's exactly what the function is built to facilitate. It's looking for the new ID for the current user, not just the newest ID. The count can't be "out of order".