In this article I will share a way to remove the user group permission from SharePoint using JavaScript object model.

Steps for implementation:

In your JavaScript file write the following code,

  1. // Js code Starts here
  2. 'use strict';
  3. //Get Current Context
  4. var context = SP.ClientContext.get_current();
  5. //Declaring the variables
  6. varhostWebURL, appWebURL;
  7. // this code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
  8. $(document).ready(function()
  9. {
  10. // Get App web URL and Host Web URL from Query string parameter
  11. hostWebURL = decodeURIComponent(manageQueryStringParameter('SPHostUrl'));
  12. appWebURL = decodeURIComponent(manageQueryStringParameter('SPAppWebUrl'));
  13. //Calling remove group method in document ready
  14. RemoveGroup();
  15. });
  16. functionRemoveGroup()
  17. {
  18. varcWeb = appCtx.get_web();
  19. varroleAssignments = cWeb.get_roleAssignments();
  20. //552 is id of user group
  21. roleAssignments.getByPrincipalId("552").deleteObject();
  22. context.load(cWeb);
  23. context.executeQueryAsync(function()
  24. {
  25. alert("success");
  26. }, function(sender, args)
  27. {
  28. alert("Request failed to change the group name " + args.get_message());
  29. });
  30. }

  31. //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.