0

I want to grant unique permission on folder level in SharePoint 2013 Library , Once a new folder is created, edit permission should be granted to the one who has created it.

I've been using the following code the grant permission, which is working fine.

 function readPermisiontoUSER(id,email) 
    
    {  

      Context = new SP.ClientContext.get_current(); 
      var Website = Context.get_web();   
      var oList = Context.get_web().get_lists().getByTitle('my_Lib');
      var ListItem = oList.getItemById(id);
           
  
    ListItem.breakRoleInheritance(false);  
    this.User = Context.get_web().get_siteUsers().getByEmail(email);  

    var collRoleDefinitionBinding = SP.RoleDefinitionBindingCollection.newObject(Context);  
    
    collRoleDefinitionBinding.add(Context.get_web().get_roleDefinitions().getByType(SP.RoleType.editor));    
    ListItem.get_roleAssignments().add(User, collRoleDefinitionBinding);   
    Context.load(User);  
    Context.load(ListItem);  
    Context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));  

}  
  
function onQuerySucceeded(sender, args) {  
  
    console.log('Role inheritance broken for item ');  
        
}  
  
function onQueryFailed(sender, args) 

{  
  
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());  
}

Now the issue is, i need to trigger this JavaScript function immediately when a new folder is created, is there any easy to achieve this ?

2
  • 1
    Did you look at the option of setting the Item level permissions, I think "Create items and edit items that were created by the user" permission is what you need. See sharepointmaven.com/… – Nadeem Yousuf-AIS Dec 24 '20 at 4:13
  • 1
    maybe event receivers or SharePoint designer workflow are more proper ways to implement this. – Raf Dec 24 '20 at 7:00
1

You can create SharePoint Designer workflow 2010 to achieve your design.

Please follow steps:

1.Go to your Library and click on "Edit library" to open SharePoint Designer 2013 enter image description here

2.Create a SharePoint 2010 Workflow named "Grant Permission"

3.Click on Impersonation Step in the ribbon menu to insert Impersonation Step before Step 1. enter image description here

4.Under the Impersonation Step, click on Condition and choose If current item field equals value from the drop down menu. enter image description here 5.Next click on the Action button on the ribbon, scroll down to the List Actions section and choose Inherit List Item Parent Permissions, and then choose Replace List Item Permissions. enter image description here

6.Under the Step 1, click on the Action button on the ribbon, scroll down to the List Actions section and choose Update List Items enter image description here

7.Save and Publish this workflow. enter image description here

2
  • thanks a lot for sharing this idea, it worked and saved me a lot of time . thanks you so much – Jegan Baskaran Dec 24 '20 at 11:28
  • Hi, Jegan Baskaran. Glad I can help you. Have a nice day! – EchoDu_MSFT Dec 25 '20 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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