Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add Geolocation field to List via SharePoint CSOM (JavaScript)
function ProvisionField(fieldSchema, listTitle,OnSuccess,OnError)
{
var context = SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle(listTitle);
var fields = list.get_fields();
var fieldToAdd = fields.addFieldAsXml(fieldSchema, true, SP.AddFieldOptions.AddToDefaultContentType);
fieldToAdd.update();
context.load(fieldToAdd);
context.executeQueryAsync(OnSuccess(fieldToAdd),OnError);
}
function AddGeolocationFieldToContactsList()
{
ProvisionField("<Field Type='Geolocation' DisplayName='Location'/>","Contacts",
function(field){
console.log('Geolocation field has been added');
},
function(sender,args){
console.log('Error occured while adding Geolocation field:' + args.get_message());
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.