0

I'm attempting to write a script that will get me all the permissions assigned to an item. Ideally I would need the group name and then their permission level (read, contribute, etc.). I got the group name but I'm not sure how to get the rest, see below

<script type="text/javascript">
function GetItemPermissions() {
    
    var ctx = new SP.ClientContext.get_current();
    var list = ctx.get_web().get_lists().getByTitle('List Name');
    var camlQuery = new SP.CamlQuery();
    var items = list.getItems(camlQuery);
    ctx.load(items, 'Include(RoleAssignments, RoleAssignments.Include(Member))');
    ctx.executeQueryAsync(function() {
        var item = items.getEnumerator();
        while (item.moveNext()) {
            var currentItem = item.get_current();       

            var GetRoles = currentItem.get_roleAssignments().getEnumerator();
            var groups = "";
            while (GetRoles.moveNext()) {
                var currentRole = GetRoles.get_current();
                var permissionType = currentRole.get_member().get_principalType();
                var permissionName = currentRole.get_member().get_loginName();
                if ( permissionType == 8 && permissionName != "Style Resource Readers") {
                    groups += permissionName + "; "
                }
            }
        }
    }, function() {})
} 

ExecuteOrDelayUntilScriptLoaded(GetItemPermissions, 'sp.js');

</script>

1

0

Your Answer

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

Browse other questions tagged or ask your own question.