2

So if I am using the COM/JSOM, and normal GetListItem, can is there something I can add to the Include method, that will allow me to see if the item returned has permissions under default inheritance or unique permissions?

I found hasUniqueRoleAssignments, effectiveBasePermissions & roleAssignments on MSDN here. However I am not sure how to get what I am looking for out of these? Just want to know when I get an item if it has unique permissions or not, and even possible what group/users are assigned to it (bonus).

2 Answers 2

5

If you want to know if a list item has unique permissions the you would use the HasUniqueRoleAssignments property. This property available in the Managed Client Object Model but it is not in the Javascript Client Object Model. Update: Anders comment was correct, the HasUniqueRoleAssignments property is available in the Javascript Client Object Model (see code sample below).

If you want to know if the current user has permissions to perform an action (e.g. delete the list item) then you would use the EffectiveBasePermissions property. This is available in both the Managed and the Javascript implementations.

Managed: ListItem Members
JavaScript: SP.ListItem properties

jQuery(document).ready(function () {
    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getByTitle("Products");
    var query = new SP.CamlQuery();
    query.set_viewXml("<View><RowLimit>1</RowLimit></View>");
    var qItems = list.getItems(query);

    var items = context.loadQuery(qItems, "Include(Title, HasUniqueRoleAssignments)");
    context.executeQueryAsync(success, fail);

    function success() {
        var item = items[0];
        var message = jQuery("#message");
        message.text(item.get_item("Title"));
        message.append("<br/>");
        message.append(item.get_hasUniqueRoleAssignments().toString());
    }

    function fail(sender, args) {
        alert('Request failed. ' + args.get_message());
    }
});        
5
  • 1
    Rob, are you sure about that. msdn.microsoft.com/en-us/library/ee549387(v=office.14).aspx, doesn't splistitem inherit from SP.SecurableObject Sep 3, 2013 at 5:42
  • Yes you are correct, I misread the documentation. I'll update my answer. Sep 3, 2013 at 6:33
  • thanks very much for the help. greatly appreciated as always.
    – Justin
    Sep 6, 2013 at 10:28
  • Adding "Include(HasUniqueRoleAssignments)" to the load sentence makes my query fail. I don't know why.
    – xero399
    Sep 23, 2019 at 7:40
  • @xero399 I suggest you post a new question that shows the code you tried and gives information about the error you are getting. Sep 23, 2019 at 15:25
1

Let me just note that if you need to do the same thing for a list instead of listItem, you'll have to 'ask' the sp.web, could not make it work any other way. This code works.

var listTitle = "myList";
var context = SP.ClientContext.get_current();
var web = context.get_web();
var collectionList = web.get_lists(); 
context.load(collectionList, 'Include(Title, HasUniqueRoleAssignments)');
context.executeQueryAsync(success, fail);

function success() {
    var listInfo = '', answerBool, listEnumerator = collectionList.getEnumerator();

    while (listEnumerator.moveNext()) {
        var oList = listEnumerator.get_current();
        if (oList.get_title() == listTitle) {
            answerBool = oList.get_hasUniqueRoleAssignments();
            break;
        }
    }
    alert(answerBool);   
}

function fail(sender, args) {
    var error = {
        sender: sender,
        args: args
    };
    console.log(error);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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