Saturday 8 December 2012

Share record with User/Team in CRM 2011 using c#


Share record with User / Team


GrantAccessRequest shareToUser = new GrantAccessRequest()
 {
  Target = new EntityReference("opportunity", opportunityId), //Entity Logical name and record Id
         PrincipalAccess = new PrincipalAccess
          {
                 Principal = new EntityReference(SystemUser.EntityLogicalName, userId_or_teamId),
                 AccessMask = AccessRights.ReadAccess | AccessRights.WriteAccess | AccessRights.ShareAccess
           }

};
GrantAccessResponse grantresponse = (GrantAccessResponse)service.Execute(shareToUser);

Remove record sharing from the User / Team

ModifyAccessRequest removeSharing = new ModifyAccessRequest
 {
  Target = new EntityReference("opportunity", opportunityId), //Entity Logical name and record Id
        PrincipalAccess = new PrincipalAccess
         {
                Principal = new EntityReference(SystemUser.EntityLogicalName, userId_or_teamId),
                AccessMask = AccessRights.None
          }
   };
ModifyAccessResponse modifyresponse = (ModifyAccessResponse)service.Execute(removeSharing);

No comments:

Post a Comment