Skip to content

Instantly share code, notes, and snippets.

@vaderj
Last active June 12, 2018 16:55
Show Gist options
  • Save vaderj/ddca933196b12de899a03f119059eaa2 to your computer and use it in GitHub Desktop.
Save vaderj/ddca933196b12de899a03f119059eaa2 to your computer and use it in GitHub Desktop.
Enable / Disable Site Collection Feature via JavaScript / ECMAScript #Javascript #SharePoint #SOAP
function OnSuccess(sender, args) {
alert("Success!");
}
function OnFail(sender, args) {
alert("Fail: " + args.get_message() + "\n" + args.get_stackTrace());
}
function ActivateFeature(url,guid)
{
var clientContext = new SP.ClientContext(url);
var site = clientContext.get_site();
var guid = new SP.Guid(guid);
var featDef = site.get_features().add(guid, false, SP.FeatureDefinitionScope.Farm);
clientContext.executeQueryAsync(Function.createDelegate(this, this.OnSuccess), Function.createDelegate(this, this.OnFail));
}
function deactivateFeature(url,guid)
{
var clientContext = new SP.ClientContext(url);
var site = clientContext.get_site();
var guid = new SP.Guid(guid);
var featDef = site.get_features().remove(guid, true);
clientContext.executeQueryAsync(Function.createDelegate(this, this.OnSuccess), Function.createDelegate(this, this.OnFail));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment