Showing posts with label SharePoint CSOM javascript Get List Fields. Show all posts
Showing posts with label SharePoint CSOM javascript Get List Fields. Show all posts

Saturday, 15 March 2014

SharePoint CSOM javascript Get List Fields

SharePoint CSOM javascript Get List Fields
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();
while(lEnum.moveNext())
{
_fields += lEnum.get_current().get_title() + " - " + lEnum.get_current().get_internalName() + ";";
}
alert(_fields);
}
function Failure(sender, args)
{
alert("Failed" + args.get_message());
}