Break The Permission In SharePoint2013 List Using JavaScript Object Model

Using this code, we can break the security inheritance of a Website, list, librar, or a list item through the BreakRoleInheritance method. When we want to grant an access to the folders or the documents or simply for an item to a specific user, we go ahead and break the Inheritance and provide an access to the specified user.
 
Open your SharePoint solution in Sharepoint Server.

Add JavaScript files given below in to your solution.
  1. <script type="text/javascript" src="../Scripts/jquery-1.9.1.min.js"></script>  
  2. <script type="text/ecmascript" src="../_layouts/SP.core.debug.js" />  
  3. <script type="text/ecmascript" src="../_layouts/SP.runtime.debug.js" />  
  4. <script type="text/ecmascript" src="../_layouts/SP.debug.js" />  
The blog given below shows how to break the security of a list by using the breakRoleInheritance(copyRoleAssignments, clearSubscopes) function of the List object.
  1. <script type="text/ecmascript">  
  2.     function breakPermision() {  
  3.         var Context = new SP.ClientContext.get_current();  
  4.         var Website = Context.get_web();  
  5.         var oList = Website.get_lists().getByTitle('CustomList');  
  6.   
  7.     oList.breakRoleInheritance(truefalse);  
  8.   
  9.     Context.load(oList);  
  10.   
  11.     Context.executeQueryAsync(Function.createDelegate(thisthis.QuerySucceeded), Function.createDelegate(thisthis.QueryFailed));  
  12. }  
  13.   
  14. function QuerySucceeded(sender, args) {  
  15.   
  16.         alert(this.oList.get_title() + ' role inheritance broken.');  
  17. }  
  18.   
  19. function QueryFailed(sender, args) {  
  20.   
  21.         alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());  
  22. }  
  23.   
  24. </script>  

Ebook Download
View all
Learn
View all