Tuesday, September 13, 2016
nice pattern for jsom async calls
pass the call backs as parameters to the function
function getSiteField(fieldName,success,failure)
{
var ctx = SP.ClientContext.get_current();
var rootWeb = ctx.get_site().get_rootWeb();
var field = rootWeb.get_availableFields().getByInternalNameOrTitle(fieldName);
ctx.load(field);
ctx.executeQueryAsync(
function(){
success(field)
},
failure);
}
SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function() {
//get Title column and print its properties
getSiteField('Title',
function(field){
//print field properties
console.log(field.get_title());
console.log(field.get_internalName());
console.log(field.get_typeAsString());
console.log(field.get_description());
},
function(sender,args){
console.log(args.get_message());
});
});
got it here
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment