GetListItems only returning rows from the person logged in.

Feb 13, 2014 at 5:03 PM
I can't figure out why my GetListItems call won't return all the items in the list. Maybe it's a permissions thing? I have everyone set to Contributor and then a few with Full Control. Here is the SPServices call:
var users = new Array();
var i = 0;
var oldName = "";

$().SPServices({
        operation: "GetListItems",
        async: false,
        listName: listName,
        CAMLViewFields: "<ViewFields><FieldRef Name='StaffName' /></ViewFields>",
        completefunc: function(xData, Status) {
            $(xData.responseXML).SPFilterNode("z:row").each(function() {
                                //if the name is already in the array then don't re-add or move index
                if(oldName != $(this).attr("ows_StaffName"))
                {
                    users[i] = $(this).attr("ows_StaffName");
                    i++;
                }
                oldName = $(this).attr("ows_StaffName");
            });
        }
    });
Can anyone see anything wrong with the above? Is there somewhere I should be checking within SharePoint that may be causing a problem?
Feb 13, 2014 at 5:20 PM
Everything above looks ok... I can only think of two things:
  1. When a CAMLQuery is not defined, I believe what is returned is whatever the default list view has defined... Try to define a camlQuery... for example where StaffName is not null. That should override whatever is defined in the default list view
  2. Does the list have any spacial permissions? like: only allow user to edit/view own items?
/Paul
Coordinator
Feb 13, 2014 at 5:24 PM
Edited Feb 13, 2014 at 5:42 PM
The Web Services will only return those items to which the current user has permissions. So yes, it could be a permissions thing.

It looks like what you are trying to do is get a unique list of StaffName values. Since you haven't sorted by that column, you will get unpredictable results.
var users = [];

$().SPServices({
    operation: "GetListItems",
    async: false,
    listName: listName,
    CAMLViewFields: "<ViewFields><FieldRef Name='StaffName' /></ViewFields>",
    CAMLQuery: "<Query><OrderBy><FieldRef Name='StaffName'/></OrderBy></Query>",
    completefunc: function(xData, Status) {
        $(xData.responseXML).SPFilterNode("z:row").each(function() {
            //if the name is already in the array then don't re-add or move index
            var thisStaffName = $(this).attr("ows_StaffName");
            if(users[thisStaffName] === undefined) {
                users.push(thisStaffName);
            }
        });
    }
});
M.
Feb 13, 2014 at 5:48 PM
Looks like it was the default view that was causing it. Thanks Paul!

Thanks for the heads up Marc!