GetListItems Not Retrieving All Records

Jul 26, 2011 at 7:22 PM

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 HR Kalendar 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) {       //alert(xData.responseText);
          	   $(xData.responseXML).find("[nodeName='z:row']").each(function() { //--------FIND EACH RECORD FROM HR KALENDAR
     		   	listCategory = $(this).attr("ows_Event_x0020_Category").split(";#").join(" "); //---------REMOVE "semi-colon, pound sign, AND comma" FROM THE MULTIPLE CATGORIES ARRAY
				$("#" + $(this).attr("ows_ID")).addClass($(this).attr("ows_Region_x002f_CC")); //------COMPARE ID FROM LIST DATA TO THE ID WE ADDED TO THE CALENDAR AND ADD REGION AS CLASS TO <TD> OF CALENDAR
				$("#" + $(this).attr("ows_ID")).addClass(listCategory); //------COMPARE ID FROM LIST DATA TO THE ID WE ADDED TO THE CALENDAR AND ADD CATEGORIES AS CLASS TO <TD> OF CALENDAR

      	  });
     	 }
    });  
   });
Jul 26, 2011 at 7:54 PM

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.

Jul 26, 2011 at 8:01 PM

You are the MAN!!!!  Thank you so much, worked like a champ my friend.  For those of you who may run into this issue i've pasted the code with iOnline247's solution below.  Thanks again.  Nice job, wish I could write CAML on the fly like that.

<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",
	  CAMLQuery: "<Query><Where><Neq><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Neq></Where></Query>",
    	  completefunc: function (xData, Status) {       //alert(xData.responseText);
          	   $(xData.responseXML).find("[nodeName='z:row']").each(function() { //--------FIND EACH RECORD FROM HR KALENDAR
     		   	listCategory = $(this).attr("ows_Event_x0020_Category").split(";#").join(" "); //---------REMOVE "semi-colon, pound sign, AND comma" FROM THE MULTIPLE CATGORIES ARRAY
				$("#" + $(this).attr("ows_ID")).addClass($(this).attr("ows_Region_x002f_CC")); //------COMPARE ID FROM LIST DATA TO THE ID WE ADDED TO THE CALENDAR AND ADD REGION AS CLASS TO <TD> OF CALENDAR
				$("#" + $(this).attr("ows_ID")).addClass(listCategory); //------COMPARE ID FROM LIST DATA TO THE ID WE ADDED TO THE CALENDAR AND ADD CATEGORIES AS CLASS TO <TD> OF CALENDAR

      	  });
     	 }
    });  
   });
Coordinator
Jul 26, 2011 at 8:47 PM
Edited Jul 26, 2011 at 8:56 PM

Generally speaking iOnline's suggestion won't 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*, you're asking SharePoint to "stop out of" the default view.

M.

p.s. This is turning into a good blog post: http://sympmarc.com/2011/07/26/tip-for-using-spservices-with-getlistitems/

Jul 26, 2011 at 8:56 PM

My default view is the admin view which displays all data.  About a month ago It was retrieving all data, it's just within the past week or so that it stopped.

Coordinator
Jul 26, 2011 at 8:59 PM

That admin view may not show the same thing to different users. For instance, you may have unapproved items.

The fact that Matt's trick worked means that there was something about the default view settings which was filtering the items returned.

M.

Jul 26, 2011 at 9:01 PM

Glad to have helped steppjos!  This actually helped me too... I was able to pull another nugget of info out of Marc's brain that I didn't know.  Nice tip Marc!

Jul 26, 2011 at 9:22 PM

It's nice to know my question was blog worthy.  You guys are awesome!  I plan on reading your book Unlocking the Mysteries of the SharePoint Data View Web Part XSL Tags.  Is this your first book or have you published others? 

Coordinator
Jul 26, 2011 at 9:28 PM

That's my only book to date, though I suppose if I gathered a lot of my blog posts together, I might have another couple! I hope that Unlocking the Mysteries of the SharePoint Data View Web Part XSL Tags proves useful for you.

Shameless promotion: I teach courses about this stuff at the USPJ Academy. Consider taking a class.

M.

Jul 26, 2011 at 10:06 PM

My first book wil be "how to ask blog worthy sharepoint questions" lol.  I'm very interested in the Tuition Program with USPJ Academy but I am located in Huntsville, Al.  Can I take this program online?

Jul 26, 2011 at 10:12 PM

Yes, the academy is completely online and it's where I've been able to learn all of my jQuery skills.  I definitely recommend it.

Coordinator
Jul 26, 2011 at 10:16 PM

It just so happens that I've started a new iteration of my Introduction to the SharePoint Web Services class today. No pressure, but...

M.

Jul 26, 2011 at 10:24 PM

My job should be able to completely fund the tuition for me.  It says I can get a bachelor in SharePoint?  How long will this take?  And when does your next classes begin?

Coordinator
Jul 26, 2011 at 10:27 PM

All the info you should need is on the USPJA site. If you have questions, send them to uspja@uspja.com. Here's a link which describes the certificate program:
http://www.uspja.com/studying-at-uspja/programs-and-courses/sharepoint-certifications/certified-sharepoint-developer

M.

Jul 26, 2011 at 10:33 PM

Sounds great.  I will get this all set up tomorrow.  Thanks for the suggestion, you too Matt.

Jul 27, 2011 at 8:52 PM
Edited Jul 27, 2011 at 10:03 PM

Marc or Matt-  Can you tell me what USPJ stands for?  I'm trying to submit your academy information into my companies tuition program.  They require the full name, address, and phone number.

Jul 27, 2011 at 10:19 PM


Here is the information for USPJ Academy.

Full Name:

Understanding SharePoint Journal

 

Full Name (billing purposes):

Understanding SharePoint LLC

 

Address:

Understanding SharePoint LLC

831 Beacon Street

Suite 118

Newton Centre, MA 02459

 

Phone Number:

+1 877 908 7752 (+1 877 90 USPJA)

Coordinator
Jul 27, 2011 at 11:57 PM

Glad you found what you were looking for. If you have any suggestion on how we can improve the information on the USPJA site, please send them to uspja@uspja.com and cc me.

M.