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

Limit Caml Query

Oct 27, 2010 at 12:03 AM
Edited Oct 27, 2010 at 12:08 AM

I am using the SP service successfully to return items, but I cant find any methods of limiting the amount of list items returned via my caml query, <rowlimit> doesnt make a difference, a JS for loop does not work either.

$(document).ready(function() {

...get list items service, CAML query, works


function processResult(xData, status) {
        $(xData.responseXML).find("z\\:row").each(function() { //iterates through each record, need a fixed number of iterations
   var Html = "<strong><a href=/sites/web/Lists/News/DispForm.aspx?ID=" + $(this).attr("ows_ID") + ">" + $(this).attr("ows_Title") + "</a></strong><br>" + $(this).attr("ows_Summary") + "<br /><br />";


I do have it ordering correctly in the populated view, but my Jquery skills are not sharp enough to make the find z rows = < 4 (fixed) rather than z for each (all). Thanks to any experts who know how to reconfigure this chunk.

Oct 27, 2010 at 2:14 AM
rowlimit ought to work. Can you post the code you've tried? BTW, z\\:row won't be a reliable selector if there's a chance that someone will use your site with other browsers. Check my blog post here: M.
Oct 27, 2010 at 3:17 PM

Thanks for the quick postback, here is the full code. I'm actually using the older Jan Tielens soap method (just found this forum and the new SP library yesterday). Is the old method the problem? Far as the z rows it would be best practice to follow your blog, but we are stuck in the stone ages using IE6 in our environment. Elvis will walk through the office before they allow non-IE broswers.

   $(document).ready(function() {
        //This is a CAML query which calls the SharePoints list contents for tab1
  var soapEnv = "<soapenv:Envelope xmlns:soapenv=''><soapenv:Body><GetListItems xmlns=''>";
  soapEnv += "<listName>News</listName>";
     soapEnv += "<query><Query><Where><Eq><FieldRef Name='_ModerationStatus' /><Value Type='ModStat'>Approved</Value></Eq></Where><OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy><RowLimit>4</RowLimit></Query></query>";
// Row limit has been put in the query, outside the query, after list name, after getlist items, not sure where else in the soap call I can place it.....
  soapEnv += "</GetListItems></soapenv:Body></soapenv:Envelope>"; 
            url: "",
            type: "POST",
            dataType: "xml",
            data: soapEnv, //Can also place soapEnv2 no errors desired is [soapEnv, soapEnv2]
            complete: processResult, //desired is [processResult, processResult2]
            contentType: "text/xml; charset=\"utf-8\""

    function processResult(xData, status) {
        $(xData.responseXML).find("z\\:row").each(function() {
   var Html = "<strong><a href=" + $(this).attr("ows_ID") + ">" + $(this).attr("ows_Title") + "</a></strong><br>" + $(this).attr("ows_Summary") + "<br /><br />";

Oct 27, 2010 at 3:57 PM

So you're not actually using SPServices, then. I'd suggest switching over and then let me know if you have problems with the SPServices approach.

You should still make the change for z:row. It's just a much safer approach, regardless whether you think you'll have other browsers or not.


Oct 27, 2010 at 5:05 PM

Thanks, I'l take the time to look through this site to see how to use this new library instead, and update the z:row use.