SPGetLastItemId Returning a '0' Value...

Apr 29, 2012 at 1:00 PM

I am using this in the PreSaveAction and on alert I see a 0 value...do I need to wrap this in GetListItems? 

var lastId = $().SPServices.SPGetLastItemId({
    listName: "MyList"
  });

Bob

Coordinator
Apr 29, 2012 at 1:18 PM
Edited Apr 29, 2012 at 1:39 PM

I think it should work as you have it. The function returns 0 if the current user doesn't have an item in the list.

M.

Apr 29, 2012 at 1:22 PM
sympmarc wrote:

I think it should work as you have it. The function returns 0 if the current user doesn't have an item on the list.

M.


I missed what you mean by user doesn't have an item in the list. This is a user who is filling in fields in a newform, I tested this as myself...

Bob

Coordinator
Apr 29, 2012 at 1:38 PM

What the function does is look in the list for the last item that the current user has created and it passes back the ID of that item. If the user has not created an item in that list previously, it will return zero. Make sense?

M.

Apr 29, 2012 at 1:55 PM

Ahhh, ok. How can I get the ID of the newly created form then? Will GetListItems work in this case?

Bob

Apr 29, 2012 at 3:11 PM

I have an idea of how to make this work using SPRedirectWithID.

Coordinator
Apr 29, 2012 at 5:03 PM

Yes, SPRedirectWithID is the one to look at. The problem is that the new ID isn't assigned until the item is committed asynchronously.

M.