Search This Blog

Thursday, October 15, 2015

Assigning Item Level permission using JSOM in Sharepoint 2013

This post contains the code to assign Item level permission using JSOM. 

function assignItemLevelPermission()
{
              
                var clientContext = new SP.ClientContext.get_current();
                var collRoleDefinitionBinding;
                var objListItem="your list item"
                collRoleDefinitionBinding = SP.RoleDefinitionBindingCollection.newObject(clientContext);
                    collRoleDefinitionBinding.add(clientContext.get_web().get_roleDefinitions().getByType(SP.RoleType.reader));
                 // Make sure you pass on the user identity as you@youroffice.com
                 var oUser= clientContext.get_web().ensureUser(“you@youroffice.com”);                
                objListItem.breakRoleInheritance(false);
                objListItem.get_roleAssignments().add(oUser, collRoleDefinitionBinding);
                objListItem.update();
                clientContext.load(oUser);
                clientContext.load(objListItem);
                clientContext.executeQueryAsync
                                                (
                                                                function onQuerySucceeded() {
                                                                   alert(‘success’);
                                                                },
                                                                function onQueryFailed() {
                                                                    alert(‘failed’);
                                                                }
                                                );

}

No comments:

Post a Comment