Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to use the javascript object model to retrieve a list of users/groups for a list and their permissions at the list level. So far I have this which returns a member object but I cant get any information about the member. When I try to use rAssignment.get_member().get_id(), or rAssignment.get_member().get_title() I get an error.

        //Get List Permissions
        function getListPerms() {
            var clientContext = new SP.ClientContext();
            var siteColl = clientContext.get_site();
            var site = clientContext.get_web();
            listSecurableObject = site.get_lists().getByTitle($("[name='ListSlct']").val());
            listRoleAssignments = listSecurableObject.get_roleAssignments();
            clientContext.load(listRoleAssignments);
            clientContext.executeQueryAsync(Function.createDelegate(this, this.getListPerms_onQuerySucceeded),Function.createDelegate(this, this.getListPerms_onQueryFailed));
       }
       function getListPerms_onQuerySucceeded() {
            var listPerms="";
            listPerms += '<table border="1">';
            listPerms += '<tr>';
            listPerms += '<td align="center">ID</td>';
            listPerms += '</tr>';
            var listPermsEnumerator =  this.listRoleAssignments.getEnumerator();
            while (listPermsEnumerator.moveNext()) {
                var rAssignment = listPermsEnumerator.get_current();
                listPerms += '<tr>';
                listPerms += '<td align="center">' + rAssignment.get_member() +  '</td>';
                listPerms += '</tr>';
            }
            listPerms += '</table>';
            document.getElementById('listPermsTable').innerHTML = listPerms;
       }
       function getListPerms_onQueryFailed(sender, args) {
           alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
       }
share|improve this question
    
It returns me the error "Error: The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested." ... Did you search on Google? Because it gave me that thread: sharepoint.stackexchange.com/questions/30828/… –  AymKdn Apr 11 '13 at 13:18
    
Yes I did, I tried requesting the ID and Title explicitly and it still threw the same error. –  AdvaComp Apr 12 '13 at 14:02

1 Answer 1

Try changing your clientContext.load() function call as follows:

clientContext.load(listSecurableObject, 'Include(RoleAssignments, RoleAssignments.Include(Member))');

Now in the getListPerms_onSucceeded() method you ought to be able to enumerate through listSecurableObject.get_roleAssignments() and get the members similar to how you're already doing it (although you'll probably want to use rAssignment.get_member().get_loginName() ).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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