The function

 var lastID = $().SPServices.SPGetLastItemId({
                        listName: 'list1'

from SPServices returns last id for items that was created by current user

I want to get the id of item which was created by current user OR on behalf of current user.

I need last id with 2 conditions that either created by current user OR

created by Add-in on behalf of current user

I see this on item details

Created at 7/20/2017 12:09 PM by app name SharePoint Add-in on behalf of :user xxxx

calling SPGetLastItemId return 0

I think there is something wrong that the last item which current user is creating does not properly set "Author" or something!


I assume, you have not set unique permissions for list items. Hence all Items of the list can be accessed by current user.

You can Query the List items, set as sorted descending by ID, and setting Rowlimit as 1. your query be like

<Query><Where><Neq><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Neq></Where><OrderBy><FieldRef Name="ID" Ascending="False" /></OrderBy></Query>

Complete working code using SPServices is:

var lastID;
    operation: "GetListItems",
    async: false,
    listName: target_List_name,     
    CAMLQuery: '<Query><Where><Neq><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Neq></Where><OrderBy><FieldRef Name="ID" Ascending="False" /></OrderBy></Query>',
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='ID' /></ViewFields>",
    CAMLRowLimit: 1,
    completefunc: function(xData,Status){
            lastID = $(this).attr("ows_ID");
| improve this answer | |
  • I don't want id of item which was created by any other user, also please check updated question details. – codemirror Jul 21 '17 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.