Question

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 ?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top