Specifing CAMLQuery results in listname blank in soap call

Mar 9, 2012 at 9:22 PM

I am running into an issue with using a CAMLQuery.  If I specify a CAMLQuery, I am getting an error back about "value out of range" after digging into I found it is caused by the fast that listName is not populated

<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'><listName></listName><viewName></viewName><query><Query><OrderBy><FieldRef Name='Functional_x0020_Area'/><FieldRef Name='LinkTitle'/></OrderBy><GroupBy Collapse='FALSE'><FieldRef Name='Functional_x0020_Area'/></GroupBy><Where><Eq><FieldRef LookupId='TRUE' Name='Environment'/><Value Type='Lookup'>1</Value></Eq></Where></Query></query><viewFields><ViewFields></ViewFields></viewFields><rowLimit>0</rowLimit><queryOptions><QueryOptions></QueryOptions></queryOptions></GetListItems></soap:Body></soap:Envelope>

if I do not specify a CAMLQuery then it does get populated.

<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'><listName>Environment Settings</listName><viewName></viewName><query></query><viewFields><ViewFields></ViewFields></viewFields><rowLimit>0</rowLimit><queryOptions><QueryOptions></QueryOptions></queryOptions></GetListItems></soap:Body></soap:Envelope>

The only thing I changed between to two calls is the CAMLQuery property in the options class.

Anyone have any thoughts?

BTW: I am using the latest version 0.7.1a

Coordinator
Mar 10, 2012 at 4:06 AM

Can you post your code?

M.

Mar 10, 2012 at 2:28 PM

Sure -- here is a small piece/example.  If I comment out the "CAMLQuey" -- it works.

var opts = {
	listName: "Environment Settings",
	columns: [
		"ID", 
		"Environment",
		"Functional_x0020_Area",
		"Setting_x0020_Type",
		"Title",
		"Setting_x0020_Value"				
	],
	CAMLQuery: "<Query><OrderBy><FieldRef Name='Functional_x0020_Area'/><FieldRef Name='LinkTitle'/></OrderBy><GroupBy Collapse='FALSE'><FieldRef Name='Functional_x0020_Area'/></GroupBy><Where><Eq><FieldRef LookupId='TRUE' Name='Environment'/><Value Type='Lookup'>1</Value></Eq></Where></Query>"
}

var camlViewFields = "<ViewFields>";
for (i = 0; i< opt.columns.length; i++){
	camlViewFields += '<FieldRef Name="' + opt.columns[i] + '" />';
}
camlViewFields += "</ViewFields>";
var data = {
	rows: [],
	errors: []
};

$().SPServices({
		operation: "GetListItems",
		async: false,
		webURL: opt.relatedWebURL,
		listName: opt.listName,
		CAMLViewFields: camlViewFields ,
		CAMLQuery: opt.CAMLQuery ,
		CAMLQueryOptions: opt.CAMLQueryOptions ,
		CAMLRowLimit: 0,
		completefunc: function(xData, Status) {
			$(xData.responseXML).find("faultcode").each(function(index, item) {
				if (opt.debug) alert($(item).text());
				data.errors.push($(item).text());					
				return;
			});
			$(xData.responseXML).find("z\\:row").each(function (index) {
				// parsing rows
				var c = {};
				for (var name in opt.columns) {
					c[name] = $(this).attr("ows_" + opt.columns[name]);
				}
				data.rows.push(c); // and adding to array
			});
			if(opt.completefunc != null) opt.completefunc(data);
		}
	});

Mar 10, 2012 at 2:36 PM

Never mind :) I think I found the cause.  I was causing the opts object to get cleared and reset when I assigned the CAMLQuery which resulted in the listName property becoming invalid.

Firebug to the rescue :)

Coordinator
Mar 12, 2012 at 1:36 AM
Edited Mar 12, 2012 at 1:36 AM

Glad you figured it out!

Note that the .find("z\\:row") syntax works in IE, but is not cross-browser friendly. Take a look at $().SPFilterNode.

M.

Mar 12, 2012 at 1:41 AM

Thanks. I tried that (the SPFilterNode) and I could not get it to work. It always returned no elements…

From: sympmarc [email removed]
Sent: Sunday, March 11, 2012 9:39 PM
To: Shawn Anderson
Subject: Re: Specifing CAMLQuery results in listname blank in soap call [SPServices:348054]

From: sympmarc

Glad you figured it out!

Note that the .find("z\\:row") syntax works in IE, but is not cro

ss-browser friendly. Take a look at $().SPFilterNode.

M.

Coordinator
Mar 12, 2012 at 1:58 AM

It should be as simple as:

$(xData.responseXML).SPFilterNode("z:row").each(function (index) {

I introduced the SPFilterNode function in SPServices v0.7.0+, and it's not in earlier versions.

M.

 

Mar 12, 2012 at 1:17 PM

I was pretty sure I had 0.7.0 – that said, I’ll double check.. Thanks.

Question – I was also looking at your Get As JSON function and love the idea. When I tested it this morning, I got back an array of objects, but the objects had not properties and no values. Is this a known issue?

Note: If I use the other Get As JSON (from the forums) it is working..

From: sympmarc [email removed]
Sent: Sunday, March 11, 2012 10:00 PM
To: Shawn Anderson
Subject: Re: Specifing CAMLQuery results in listname blank in soap call [SPServices:348054]

From: sympmarc

It should be as simple as:

$(xData.responseXML).SPFilterNode("z:row").each(function (index) {

I introduced the SPFilterNode function in SPServices v0.7.0+, and it's not in earlier versions.

M.

Coordinator
Mar 12, 2012 at 1:39 PM

The $().SPXmlToJson function ought to work. I added that function in v0.7.1, but I haven't had any real reports about it working well or not. Let me if you see issues and we can try to work them through.

M.