rs:name retrieval / ows_issues

Aug 22, 2012 at 7:27 AM

Hi - maybe this has come up before. Using SpServices i can easily loop the ows_variable using the returned loop. But i have a situation where sharepoint adds it's usual nonsense into the title one creates for the column e.g (a column named 1 becomes - ows_x0031_ or 1.1 becomes ows_x0031_x002e_1 ).

It's a pain in the arse. I figure the only way to get around it is to loop the rs:names first then create and array of viewfields which i can then send to retrieve the data.

but i am struggling to loop thro those rs:names. I currently using the following line for the returned SPservices call:

$(xData.responseXML).find('s:AttributeType, name').slowEach(20, function(){

 

}

any clues as to what i'm doing wrong?

regards

mark

 

p.s the slowEach is simply a delayed called i added as browsers like I.E 80 hang when rendering on the page. so we delay the loops which sorted out the rendering problem.

 

Aug 22, 2012 at 12:39 PM

The easiest way to do this is to use a method similar to what I have in roboCAML.  Here's straight from the source:

GetList = function( opt, internalUsage ) {
	//debugger;
	//Return listProperties if already cached.
	if ( listProperties[ opt.listName ] ) {
		//console.log( "returning cached results");
		//console.dir( listProperties[ opt.listName] );
		return listProperties[ opt.listName ];
	}

	if ( !internalUsage ) {
		//Determines if webURL was passed in.  Defines opt.webURL accordingly.
		//get web url, fix the yabbage if needed.
		if ( !opt.hasOwnProperty("webURL") ) {
			//use the passed in param.
			opt.webURL = GetWeb();
		}
		if ( opt.webURL.charAt( opt.webURL.length - 1 ) === "/" ) {
			opt.webURL += ajaxURL;
		} else if ( opt.webURL.length > 0 ) {
			opt.webURL += "/" + ajaxURL;
		}
	}

	//Object to be returned w/ list information
	var returnProps = {},
	 soapEnv = SOAPEnvelope.header +
	   "<GetList xmlns='http://schemas.microsoft.com/sharepoint/soap/'><listName>" + opt.listName + "</listName></GetList>" +
	   SOAPEnvelope.footer

	; //local vars

	$.ajax({
		url: opt.webURL,
		async: false,
		type: "POST",
		data: soapEnv,
		dataType: "xml",
		contentType: "text/xml;charset='utf-8'",
		complete: function(xData, Status) {
			//console.log(Status);
			//console.log(xData.responseText);
			//console.log(xData.responseXML.xml);
			$(xData.responseXML).find("Fields > Field").each( function() {
				var $node = $(this);
				//console.log( "Type: " + $(this).attr("Type") + " StaticName: " + $(this).attr("StaticName") );

				if ( $node.attr("StaticName") ) {
					returnProps[ $node.attr("StaticName") ] = $node.attr("Type");
				} else {
					//Fixed edge case when StaticName is undefined
					returnProps[ $node.attr("Name") ] = $node.attr("Type");
				}
			});
		}
	});
	return returnProps;
};

 

Above is a call to the "GetList" operation.  You can simply use SPServices to accomplish the same thing.  This will get all of the "StaticNames" from the list you want and return them when the function is complete.  You can then cache that result accordingly.

I know Marc has implemented a caching mechanism in SPServices, but I haven't had a chance to look at it in depth.  You may want to take a peek at that as well.

 

Cheers,
Matt 

Coordinator
Sep 11, 2012 at 1:02 PM

I'm not sure that the caching will play in this, but GetList is definitely the helper here. By calling it first, you can get all of the details for the list, including the StaticNames and DisplayNames. I use GetList a lot in SPServices. The caching in v0.7.2 will simply save the results using .data() so that we don't need multiple calls for the same list in the page lifecycle.

M.