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,
- // Js code Starts here
- 'use strict';
- //Get Current Context
- var context = SP.ClientContext.get_current();
- //Declaring the variables
- varhostWebURL, appWebURL;
- // this code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
- $(document).ready(function()
- {
- // Get App web URL and Host Web URL from Query string parameter
- hostWebURL = decodeURIComponent(manageQueryStringParameter('SPHostUrl'));
- appWebURL = decodeURIComponent(manageQueryStringParameter('SPAppWebUrl'));
- //Calling remove group method in document ready
- RemoveGroup();
- });
- functionRemoveGroup()
- {
- varcWeb = appCtx.get_web();
- varroleAssignments = cWeb.get_roleAssignments();
- //552 is id of user group
- 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 valuefunction 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];}}}
In this article we explored how to remove the user group permission from SharePoint site using JavaScript object model.

Sibeesh VenuPosted Dec 24, 2015, 3:44 AM
Nice Share
Humayun Kabir MamunPosted Dec 24, 2015, 12:01 AM
Nice...
Santhakumar MunuswamyPosted Dec 23, 2015, 10:33 AM
Thanks for sharing