Created
January 13, 2014 20:44
-
-
Save vgrem/8407763 to your computer and use it in GitHub Desktop.
Add Geolocation field to List via SharePoint CSOM (JavaScript)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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