1

I have a folder in document library and each folder in it has unique permissions.

enter image description here

Now I need to retrieve the permission group names attached to it using javascript only. On click of advanced as given below

enter image description here

We get the groups and users who have permission to the folder.

enter image description here

I need only the SharePoint group names as the output using Javascript.

Can you please help me with this.

Thanks in advance

2

I think you should first get all unique permission for a folder using get_roleAssignments(), then check if the retrieved permission type get_principalType() only equals to SharePoint Group.

Download the JS script from GitHub and check the details at How to Get SharePoint Folder Permissions Using JavaScript filtered by Groups or Users?

1
  • Hi, Can you please help me with this. My code isn't working with the follwing line. var GetRoles = curruntFolder.get_roleAssignments().getEnumerator(); Till role assignments its working. Then getEnumenrator() the code is stuck there. thanks in advance Feb 15 at 3:48
1

You could use jQuery Ajax with REST API to achieve it.

The following code for your reference:

<script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {      
    getFoldersRoleAssignments("Documents"); //Enter your Library name
});
    
function getFoldersRoleAssignments(listName){

    var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/GetFolderByServerRelativeUrl('"+listName+"')/folders?$expand=ListItemAllFields/RoleAssignments/Member";

    $.ajax({
        url: requestUri,
        type: "GET",
        contentType: "application/json;odata=verbose",
         headers: { "Accept": "application/json;odata=verbose"},
        success: function (data) {
            var html="";
            var folders=data.d.results;
            for(var i=0;i<folders.length;i++){          
                if(folders[i].ListItemAllFields.RoleAssignments!=null){
                    html+="<b><p>Folder Name: "+folders[i].Name+"</p></b>";
                    var roleAssignments=folders[i].ListItemAllFields.RoleAssignments.results;
                    for(var j=0;j<roleAssignments.length;j++){
                        html+="<p>"+roleAssignments[j].Member.Title+"</p>";
                    }
                }               
            }
            $("#foldersPermissions").html(html);
        },
        error: function (e) {
            //alert("Failed to get details");                
        }
    });
}
</script>
<div id="foldersPermissions"></div>

enter image description here

1
  • $("#foldersPermissions").html(html); In this statement where do you declare $("#foldersPermissions") Feb 12 at 9:47

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.