In this article I will share a way to remove the user group permission from SharePoint using JavaScript object model.
Steps for implementation:
- Get Current Context.
- Get App web URL and Host Web URL from Query string parameter.
- Calling RemoveGroup method in document ready.
- Get web from app context site.
- Get RollAssignment from host web site.
- Then delete the object using principle ID (User Group ID)
- Finally group will be removed from SharePoint site as expected.
In your JavaScript file write the following code,
-
- 'use strict';
-
- var context = SP.ClientContext.get_current();
-
- varhostWebURL, appWebURL;
-
- $(document).ready(function()
-
- {
-
- hostWebURL = decodeURIComponent(manageQueryStringParameter('SPHostUrl'));
- appWebURL = decodeURIComponent(manageQueryStringParameter('SPAppWebUrl'));
-
- RemoveGroup();
- });
- functionRemoveGroup()
- {
- varcWeb = appCtx.get_web();
- varroleAssignments = cWeb.get_roleAssignments();
-
- roleAssignments.getByPrincipalId("552").deleteObject();
- context.load(cWeb);
- context.executeQueryAsync(function()
- {
- alert("success");
- }, function(sender, args)
- {
- alert("Request failed to change the group name " + args.get_message());
- });
- }
//method for read query string value
function manageQueryStringParameter(paramToRetrieve) {
var params = document.URL.split("?")[1].split("&");
var strParams = "";
for (var i = 0; i < params.length; i = i + 1) {
var singleParam = params[i].split("=");
if (singleParam[0] == paramToRetrieve) {
return singleParam[1];
}
}
}
Summary
In this article we explored how to remove the user group permission from SharePoint site using JavaScript object model.