This project has moved and is read-only. For the latest updates, please go here.




Certified for SharePoint 2007 Certified for SharePoint 2010


Function to return the ID of the last item created on a list by a specific user. Useful for maintaining parent/child relationships. This function was built for use by the $().SPServices.SPRedirectWithID function, but is also useful in other circumstances.




	webURL: "",
	listName: "",
	userAccount: "",
	CAMLQuery: ""

The URL of the Web (site) which contains the listName. If not specified, the current site is used. Examples would be: "/", "/Accounting", "/Departments/HR", etc. Note: It's always best to use relative URLs.

The name or GUID of the list. If you choose to use the GUID, it should look like: "{E73FEA09-CF8F-4B30-88C7-6FA996EE1706}". Note also that if you use the GUID, you do not need to specify the relationshipWebURL if the list is in another site.

The account for the user in DOMAIN\username format. If not specified, the current user is used.

The CAMLQuery option allows you to specify an additional filter on the relationshipList. The additional filter will be <And>ed with the existing CAML which is checking for matching items based on the parentColumn selection. Bacause it is combined with the CAML required to make the function work, CAMLQuery here should contain a CAML fragment such as:

CAMLQuery: "<Eq><FieldRef Name='Status'/><Value Type='Text'>Active</Value></Eq>"


The following example will return the most recently created item's ID for the current user from the States list in the current site.

<script language="javascript" type="text/javascript" src="../../jQuery%20Libraries/jquery-1.4.1.min.js"></script>
<script language="javascript" type="text/javascript" src="../../jQuery%20Libraries/jquery.SPServices-0.5.1.min.js"></script>
<script language="javascript" type="text/javascript">
  var lastId = $().SPServices.SPGetLastItemId({ 
    listName: "States"

Last edited Feb 25, 2011 at 10:45 PM by sympmarc, version 12


Vladimir_DKA Oct 28, 2015 at 9:15 AM 
For me the reason function returns 0 was in SPGetCurrentSite function. It was returning wrong url string (http://contost:81178117/sites/demo) with double port substring.
Fixed it with following regex:
$.fn.SPServices.SPGetCurrentSite = function () {
// We've already determined the current site...
var urlPattern = new RegExp("^(?:(https?)://)?([-\w_\.]{2,}\.[a-z]{2,4})(/\S*)?$");//ADDED REGEX
if (currentContext.thisSite.length > 0 && urlPattern.test(currentContext.thisSite)) {
return currentContext.thisSite;
}; // End $.fn.SPServices.SPGetCurrentSite

premsshrestha Jun 11, 2012 at 7:14 PM 
The last returned ID is always 0 now for some reason. It was working and all of sudden nor working...

premsshrestha Jun 11, 2012 at 7:13 PM 
It STOPPED working for me today...

Anyone facing similar issue?? Thanks.

sympmarc Oct 29, 2010 at 3:19 PM 
It's built to work for a specific user. However, the highest current ID number would tell you which item was most recently created. Pretty simple to do with jQuery and GetListItems.

variable Oct 28, 2010 at 5:48 PM 
Can I use this to get the last item ID on a list by ANY user? Thanks.