Table of Contents

In this article, we will see 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:

// Js code Starts here
  
'use strict';
  
//Get Current Context
  
var context = SP.ClientContext.get_current();
  
//Declaring the variables
  
var hostWebURL, 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 ();
  
});
  
function RemoveGroup()
  
{
  
    var cWeb = appCtx.get_web(); 
  
    var roleAssignments = cWeb.get_roleAssignments();
  
   //552 is id of user group
  
    roleAssignments.getByPrincipalId("552").deleteObject();
  
    context.load(cWeb);
  
    context.executeQueryAsync(function () {
&nbsspan>//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());
  
    });
  
}