GetList sample code

Dec 1, 2011 at 9:43 PM

Here's another one I built today, but didn't see a sample for:

$().SPServices({
	operation: "GetList",
	listName: "Master List",
	completefunc: function(xData, Status) {
		console.log(xData.responseText);
		$(xData.responseXML).find("Fields > Field").each(function() {
			var $node = $(this);
			console.log( "Type: " + $node.attr("Type") + " StaticName: " + $node.attr("StaticName") );
		});
	}
});

Thanks for adding the other one...

Cheers!

Coordinator
Dec 4, 2011 at 8:09 PM

Added to GetList documentation.

M.

Dec 7, 2011 at 2:22 PM

Matt,

I have played around with this with little success at what I am trying to accomplish...hoping you could let me know if this would be the right tool, and if so, point me in the right direction.

My end game is to use SPArrangeChoices to make all 120 radiobutton columns I have for a particular list be in a row of 3 (all have the same 3 choices).  To do so, I would need to provide to SPArrangeChoices the Display Name of all the columns I have of type "SPFieldChoice".  The client can change the display name without my intervention, so I need something that will do this dynamically.

Is GetList the way to go?  I am a js jQuery novice, so any guidance would be appreciated.

Thanks!

Bill

Dec 7, 2011 at 3:11 PM

Think I have a workable solution, although it takes awhile since it looks at all fields, etc...

Let me know if you think of anything cleaner....

$().SPServices({
  operation: "GetList",
  listName: "{list guid here}",
  completefunc: function(xData, Status) {
      $(xData.responseXML).find("Fields>Field").each(function() {
	var $node = $(this);
        var type = $node.attr("Type"); 
        var dispName = $node.attr("DisplayName");
   if(type=="Choice"){
     $().SPServices.SPArrangeChoices({
	columnName: dispName,
	perRow: 7
        });
     }
     });
   }
});

Dec 7, 2011 at 8:47 PM

I think you have something that will work.  The GUID is a concern if you are trying to make this a portable solution.  That may not be a concern here though.

Cheers,

Dec 7, 2011 at 9:19 PM

True, I could have the code glean the list name from the URL - that would make it drag and drop ready for any form...

var thisList = $().SPServices.SPListNameFromUrl();

$().SPServices({
  operation: "GetList",
  listName: thisList,
  completefunc: function(xData, Status) {
      $(xData.responseXML).find("Fields>Field").each(function() {
	var $node = $(this);
        var type = $node.attr("Type"); 
        var dispName = $node.attr("DisplayName");
   if(type=="Choice"){
     $().SPServices.SPArrangeChoices({
	columnName: dispName,
	perRow: 7
        });
     }
     });
   }
});

Thanks for the tip!

Bill