I have created an addin . I want when the default page loads , so i have to use javascript , to assign unique permissions to only two groups :

Leave Request Members Leave Request Managers

Permissions should be assigned in whole add-in. So in all the lists

Can anyone help me how to do this?

1 Answer 1


Break role inheritance:

<script language="javascript" type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>  
<script language="javascript" type="text/javascript">  
        SP.SOD.executeFunc('sp.js', 'SP.ClientContext', breakInheritance);  

    function breakInheritance()  
        //Get the client context and list object    
        var clientContext = new SP.ClientContext.get_current();  
        var oList = clientContext.get_web().get_lists().getByTitle('DemoList');  
        //Break inheritence    
        oList.breakRoleInheritance(true, false);  
        //Load the client context and execcute the batch    
        clientContext.executeQueryAsync(QuerySuccess, QueryFailure);  

    function QuerySuccess()  
        console.log("Inheritence has been broken.");  

    function QueryFailure(sender, args)  
        console.log('Request failed' + args.get_message());  

Assign permission to Group:

function ChangePermissions(groupMembershipID,permissionLevel) {
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
        var clientContext = SP.ClientContext.get_current();
        var web = clientContext.get_web();
        //Get Role Definition by name
        var roleDef = web.get_roleDefinitions().getByName(permissionLevel);
        var roleDefBinding = SP.RoleDefinitionBindingCollection.newObject(clientContext);
        // Add the role to the role definiiton binding.
        // Get the RoleAssignmentCollection for the web.
        var assignments = web.get_roleAssignments();
        //Get the role assignment for the group using Group  's membership id
        var groupRoleAssignment = assignments.getByPrincipalId(groupMembershipID);
        clientContext.executeQueryAsync(function () {
            alert("Permissions changed !");
                function (sender, args) {

Refer: Change Permission of a SharePoint Group using Javascript CSOM

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.