CSOM Get List Fields

Posted here for self-reference. This is how to get all fields within a list using client object model. The output is logged to the javascript console. Very handy when you’re trying to get internal/hidden field names without having to go to PowerShell or deploy custom code. In my case I needed some of the hidden attributes within picture libraries.

var fields;

function GetFieldsForList(ListName)
	var ctx = new SP.ClientContext.get_current();
	var list = ctx.get_web().get_lists().getByTitle(ListName);
	this.fields = list.get_fields();
	ctx.load(fields, 'Include(Title,InternalName)');
	ctx.executeQueryAsync(Function.createDelegate(this, this.Success), Function.createDelegate(this, this.Failure));

function Success()
	var _fields = '';
	var lEnum = fields.getEnumerator();
		_fields += lEnum.get_current().get_title() + " - " + lEnum.get_current().get_internalName() + ";";
function Failure(sender, args)
	console.log("Failed" + args.get_message());

  1. No comments yet.
(will not be published)

%d bloggers like this: