Tip for Using SPServices with GetListItems

As is often the case, one of the threads on the SPServices Discussions seemed worth bringing over as a blog post. Here’s the initial question, with the script cleaned up a little for clarity:

Any help on this would be greatly appreciated.  When I first completed this project last month it was pulling all of the data from the list.  Now when this script runs it’s only pulling back 4 out of 16 records.  Can you help me adjust the code to force it to pull all list items?

<script type="text/javascript" language="javascript" src="../../Style Library/jquery_library/jquery-1.5.2.min.js"></script>
<script type="text/javascript" language="javascript" src= "../../Style Library/jquery_library/jquery.SPServices-0.6.1.min.js"></script>
<script language="javascript" type="text/javascript">
  $(function () {//-----------SPSERVICES GET ALL LIST ITEMS FROM HR KALENDAR
    $().SPServices({
      operation: "GetListItems",
      async: false,
      listName: "HR Kalendar",
      completefunc: function (xData, Status) {
        $(xData.responseXML).find("[nodeName='z:row']").each(function() { //--------FIND EACH RECORD FROM HR KALENDAR
          ...
        });
      }
    });
  });

Matt Bramer (@iOnline247) was nice enough to reply with this suggestion:

What happens if you put a CAML query in there that says ID != 0

<Query><Where><Neq><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Neq></Where></Query>

I just wrote this query out by hand, so it may need some tweaking.  Throw that into your call and see what happens.

Generally speaking Matt’s suggestion may not be necessary. However, if you don’t specify any CAML options at all, GetListItems uses the default view for the list. That view may or may not return what you think you’ve asked for. By specifying *something* for the options, you’re asking SharePoint to “step out of” the default view.

In SPServices itself, I generally do this by specifying:

// Override the default view rowlimit and get all appropriate rows
CAMLRowLimit: 0,

The nice thing about setting the CAMLRowLimit is that you only need to pass zero as a parameter to make SharePoint stop thinking in terms of the default view. It’s simple, but effective, and doesn’t require any knowledge of CAML at all.

Similar Posts

16 Comments

  1. Hi,
    I am trying to access the SP webservice through an external site. I pretty much implemented the standard SPServices basic example to “GetListItems” but keep running into what seems to be an authentication issue. I tried all sorts of authentication settings on IIS manager to no avail :

    http://mysite/_vti_bin/Lists.asmx returns a 403.

    Any idea?

    Thanks

    1. Matthieu:

      I’d suggest looking at the Net traffic with Firebug or Fiddler to see if you can get any clues on what is causing the error.

      M.

  2. Hello Everyone,
    I am using GetListItems to display list items in site pages using CEWP. If the list item is of TypeA, its displayed in SiteA using one CEWP. If its of TypeB, its displayed in SiteB using another CEWP. And it works perfect. But if I put the two CEWP in a single site page or web part page, then both the CEWPs display same items i.e. either TypeA or TypeB. All the variables, class and ids are different in both the files that the two CEWPs are using but still no result.
    Can anyone suggest me what I might be missing?

  3. Hi Sir,

    This Blog has helped me a lot from the time i have started sharepoint programming.
    I sincerely want to thank you for your valuable help through this blog.

    I had a doubt.

    Can we get data from 3 lists on page load using sp services.

    for ex; – i have 3 lists A,B,C whose list data(Title column) i have to
    display in dropdowns using spservices where i use caml query to retreive list data ordered by created column instead of title column.

    Can you please guide me with this.

  4. Hi Marc,

    Will everything I have seen above I am having this error. I have made a mobil epage using jquery mobile and SPServices to get items from the list. I am doing this all on my machine running a VM that has Sharepoint 2010 Foundation on it. If I go to this mobile page using the server name it pulls all the items from the list. If I use the IP address then it only shows me one item which happens to be the item that was preloaded in the list by Sharepoint.

    Any ideas?

    Thank you

      1. I totally understand that and once this all goes live we are going to be connecting to the mobile page that I have created using a normal url as that Sharepoint site it’s been made for is externally facing but at the moment when connecting on my mobile phone using the server name everything renders weirdly but via the ip address it will render fine but then I have the issue of it not bringing back all the list items but instead just the one.

  5. Hi Marc its mean again and I am no longer using the ip address but set a static dns using dyndns so I have an actual domain name to work with and still the same issue. Even if I remove all the jquery mobile code and libraries and only use jquery 1.10.1 and SPServices libraries and using the SPServices getlistitem function and call from an announcements list.

    When on my host machine if I connect via the server name I get all items in that’s list but if I use the url t_____2013.dyndns.za.org/virtual directory alias/index.html I only get one item returned for the list. There must be a bug somewhere or something I am missing?

    Thank you for you time.

  6. Mark ,

    Wonder if I can get some assistance. I have used a bunch of your stuff in the past its great by the way. I know want to try to getlistitems this way. I used the following piece

    $(document).ready(function() {//———–SPSERVICES GET ALL LIST ITEMS FROM VendorCategory
    alert(“test1”);
    $().SPServices({
    operation: “GetListItems”,
    async: false,
    listName: “VendorCategory”,
    // CAMLViewFields: “”,
    CAMLViewFields: “”,
    completefunc: function (xData, Status) {
    alert(“Test2”);
    $(xData.responseXML).SPFilterNode(“z:row”).each(function() { //——–FIND EACH RECORD FROM VendorCategory
    // $(xData.responseXML).find(“[nodeName=’z:row’]”).each(function() {
    alert(“Test3”);
    var liHtml = “” + $(this).attr(“CategoryImage”) + “”;
    });
    }
    });
    });

    I can get alert test1 and test2 to fire. I can not get test3 to fire. Got any clue what I am doing wrong

    1. David:

      Odds are the Test3 alert isn’t firing because you’re getting no items back due to some error. Take a look at the network traffic in Firebug or similar to see what the returned XML looks like.

      BTW, the best place to post questions about SPServices is in the Codeplex site discussions.

      M.

  7. Hey Marc,
    Really appreciate for your nice work. I have one question,
    Is there any chance of getting list items with the list id not with the internal name?
    listName parameter will take display name of the list or internal name of the list?

    Thanks,
    Mihir

  8. Hi Marc,

    Is it possible to get the list items by it’s view name (public view). I refer some articles which is not working for me..

Leave a Reply to Travis Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.