Thursday, January 7, 2021

Change permissions of a SharePoint list using JavaScript?

Break role inheritance for a List object and grant Full Control permissions for a current user



 var listTitle = 'Documents';

var spCtx = SP.ClientContext.get_current();

var list = spCtx.get_web().get_lists().getByTitle(listTitle);   


spCtx.load(list,'HasUniqueRoleAssignments'); 

spCtx.executeQueryAsync(

   function(){

      var hasUniqueAssgns = list.get_hasUniqueRoleAssignments();

      if(!hasUniqueAssgns) {

         list.breakRoleInheritance(false, true);

         spCtx.executeQueryAsync(

            function(){

                console.log('Success');

            }, 

            function(sender,args){

               console.log(args.get_message());    

            }

         );

      }

   }, 

   function(sender,args){

      console.log(args.get_message());    

   }

);

No comments:

Post a Comment