SPServices Issue..

Nov 20, 2012 at 5:52 PM
Edited Nov 20, 2012 at 5:54 PM

Before my question, I just want to thank you for such a great plugin. It has saved me a ton of time and headache, and even taught me a thing or two about SharePoint!

I've used it successfully to display list data for a number of things, however, have come across a stumbling block yesterday. I'm not 100% if it's something simple I need to adjust on my end to make it work or not.

I'm using SPServices to pull a list and display entries to a (region - category specific) FAQ, outputting them into a div structure I am applying the jQuery UI accordion function to.

My code is below:


<script type="text/javascript" language="javascript">
                        $(document).ready(function() {
                        var fieldsToRead =     "<ViewFields>" +
                        "<FieldRef Name='Region' />" +	
                        "<FieldRef Name='Category' />" +	
                        "<FieldRef Name='Question' />" +	
                        "<FieldRef Name='Answer' />" +			
                          var query = "<Query>" +
      					"<Where>" +
      					"<And>" +
                        "<Eq>" +
                        "<FieldRef Name='Region' /><Value Type='Text'>USA</Value>" +
                        "</Eq>" +
                        "<Eq>" +
                        "<FieldRef Name='Category' /><Value Type='Text'>Benefits</Value>" +
                        "</Eq>" +
                        "</And>" +
                        "</Where>" +                        
                        "<OrderBy>" +
                        "<FieldRef Name='Question' Ascending='True' />" +
                        "</OrderBy>" +
                        operation: "GetListItems",
                        async: false,
                        webURL: '/hr',
                        listName: 'FAQ Content',
                        CAMLViewFields: fieldsToRead,
                        CAMLQuery: query,
                        completefunc: function (xData, Status) {
                        $(xData.responseXML).SPFilterNode("z:row").each(function() {
 						var acHtml = "<h3>" + $(this).attr("ows_Question") + "</h3><div>" + $(this).attr("ows_Answer") + "</div>";                 
                        <!-- FAQ Benefits -->
                        <div id="#accordion"></div>
                        <!-- END FAQ Benefits -->



Now, using firebug, I see the POST works fine and the Response shows the 6 list entries I need, tagged region:USA and category:Benefits, which so far is what I need. I'm assuming it should then display ows_Question and ows_Answer from the list entries equal to USA and Benefits.. However, the entries aren't being outputted to the #accordion div I specify. This code works with every other list (slideshows, IT announcements, etc) I've thrown at it, which leads me to believe its possibly something simple I need to adjust in the code I'm using?

This is one component of our intranet I would *love* to get working as it lends itself to a ton of other scenarios which I would be using the same idea to display info.

Thanks in advance for any help!


Nov 20, 2012 at 7:49 PM


Glad you find SPServices helpful!

I don't see anything obviously wrong. When you look at the results in Firebug, are you seeing the ows_Question and ows_Answer values in each row?


Nov 20, 2012 at 8:03 PM

Hi Marc, Thanks for the reply :)

What's weird is I definitely see the intended results. Here is a paste from Firebug of one of the results:

<z:row ows_Region='1;#USA' ows_Category='1;#Benefits' ows_Question='Can I carry over unused sick days to the next year?' ows_Answer='<div class=";ExternalClass0236D44D1DF74C018B26745C54145CC9">No, paid sick days are offered for that calendar year only and are only to be used in instances where you cannot be in the office due to illness.<;/div>' ows_MetaInfo='7;#' ows__ModerationStatus='0' ows__Level='1' ows_ID='7' ows_UniqueId='7;#{3F6ABEF0-DBA1-4B52-9A43-723ABB91C816}' ows_owshiddenversion='1' ows_FSObjType='7;#0' ows_Created='2012-11-19 12:24:46' ows_PermMask='0x7fffffffffffffff' ows_Modified='2012-11-19 12:24:46' ows_FileRef='7;#hr/Lists/FAQ Content/7_.000' />

I've pasted a webpart I use SPServices on to the exact same page to see if it remains functional, and it works (it's an IT announcement list), so I know that spservices is functional.. I'm thinking this should work no problem though, I might have to go back to some trial and error work..



Nov 20, 2012 at 8:39 PM

I'm still not seeing anything wrong with what you're doing. I guess it's back to debugging.

Is anything at all making it into the accordion div?


Nov 20, 2012 at 11:40 PM

Looks like I had the Region/Category in the wrong place.

I Figured out I needed the question and answer columns placed in the fields to read area, and then query the region / category.

A bit of trial and error involved but eventually its all working!

Thanks again for an amazing library!!

Nov 21, 2012 at 4:31 AM

Well, I don't see those issues above, but hey, you got it working, so all is good.