Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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).

share|improve this question

2 Answers 2

up vote 4 down vote accepted

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());
    }
});        
share|improve this answer
    
Rob, are you sure about that. msdn.microsoft.com/en-us/library/ee549387(v=office.14).aspx, doesn't splistitem inherit from SP.SecurableObject –  Anders Aune Sep 3 '13 at 5:42
    
Yes you are correct, I misread the documentation. I'll update my answer. –  Rob Windsor Sep 3 '13 at 6:33
    
thanks very much for the help. greatly appreciated as always. –  Justin Sep 6 '13 at 10:28

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);
}
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.