I have a SP Sub-site with broken inheritance.
Using Javascript and SharePoint Client Side API, I want to add an existing SP Group from Site-Collection to the sub-site with full-control permission level access.
Can anyone help how can I do this?
I have tried some sample code, code is running with no errors but it is not adding that group to the subsite, any help would be appreciated.
Below is my code:
function createSPGroup()
{
//Load new Site
var currentCTX = new SP.ClientContext();
var currentWEB = currentCTX.get_web('/subsiteUrl');
//Get all groups in site
var groupCollection = currentWEB.get_siteGroups();
// my group
var leadershipGRP = currentWEB.get_siteGroups().getByName("Group Name");
var rdFullControl = currentWEB.get_roleDefinitions().getByName('Full Control');
// Create a new RoleDefinitionBindingCollection.
var collFullControl = SP.RoleDefinitionBindingCollection.newObject(currentCTX);
// Add the role to the collection.
collFullControl.add(rdFullControl);
// Get the RoleAssignmentCollection for the target web.
var assignments = currentWEB.get_roleAssignments();
// assign the group to the new RoleDefinitionBindingCollection.
var roleAssignmentLeadership = assignments.add(leadershipGRP, collFullControl);
currentWEB.update();
currentCTX.load(leadershipGRP);
currentCTX.load(roleAssignmentLeadership);
currentCTX.executeQueryAsync(Function.createDelegate(this, success), Function.createDelegate(this, this.failed));
}
Please remember to click 'Mark as Answer' on the post that helps you or "Vote As Helpful"