Skip to content

Instantly share code, notes, and snippets.

@IAMIronmanSam
Created July 29, 2016 19:08
Show Gist options
  • Save IAMIronmanSam/e4f83c2774d4c44e4e20904a54111ea8 to your computer and use it in GitHub Desktop.
Save IAMIronmanSam/e4f83c2774d4c44e4e20904a54111ea8 to your computer and use it in GitHub Desktop.
Get field types & field name from list
function GetFieldsForList(Site, ListName)
{
var ctx = new SP.ClientContext(Site);
var list = ctx.get_web().get_lists().getByTitle(ListName);
this.fields = list.get_fields();
ctx.load(fields, 'Include(Title,InternalName,FieldTypeKind)');
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() + " - "+lEnum.get_current().get_fieldTypeKind()+";";
}
console.log(_fields);
}
function Failure(sender, args)
{
console.log("Failed" + args.get_message());
}
GetFieldsForList('https://mydomain.sharepoint.com/sites/mysite/','profile')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment