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.
- <script type="text/javascript" src="../Scripts/jquery-1.9.1.min.js"></script>
- <script type="text/ecmascript" src="../_layouts/SP.core.debug.js" />
- <script type="text/ecmascript" src="../_layouts/SP.runtime.debug.js" />
- <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.
- <script type="text/ecmascript">
- function breakPermision() {
- var Context = new SP.ClientContext.get_current();
- var Website = Context.get_web();
- var oList = Website.get_lists().getByTitle('CustomList');
-
- oList.breakRoleInheritance(true, false);
-
- Context.load(oList);
-
- Context.executeQueryAsync(Function.createDelegate(this, this.QuerySucceeded), Function.createDelegate(this, this.QueryFailed));
- }
-
- function QuerySucceeded(sender, args) {
-
- alert(this.oList.get_title() + ' role inheritance broken.');
- }
-
- function QueryFailed(sender, args) {
-
- alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
- }
-
- </script>