0

I've System Administrator rights at Dynamics CRM 2011 onPrem. I've following code snippet to share records to users belongs to sub business unit.

 GrantAccessRequest grantRequest = shareRecord(userId, recordId, entity);
 GrantAccessResponse grantResponse = (GrantAccessResponse)service.Execute(grantRequest);

 private GrantAccessRequest shareRecord(Guid userId, Guid recordId,string entity)
{
    GrantAccessRequest grantRequest = new GrantAccessRequest()
    {
        Target = new EntityReference(entity, recordId),
        PrincipalAccess = new PrincipalAccess() {
        Principal = new EntityReference("systemuser",userId),
        AccessMask = AccessRights.WriteAccess|AccessRights.ReadAccess|AccessRights.ShareAccess
        }
    };
    return grantRequest;
}

But I face following exception:

SecLib::AccessCheckEx failed. 
Returned hr = -2147187962, ObjectID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, 
OwnerId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,  
OwnerIdType: 8 and CallingUser: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. 
ObjectTypeCode: 10048, objectBusinessUnitId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, 
AccessRights: 262155 

I could not found any way to resolve the issue. Any help will highly be appriciated.

Mohsin Tester
  • 35
  • 1
  • 8
  • Can you double-check that the CallingUser from the error message is in fact System Administrator, as you mention? You can do this by e.g. comparing the guid of the CallingUser with your SystemUser guid. – Henrik H Jan 12 '16 at 10:15
  • It is same guid as that of the child user its not of that like sys. Admin – Mohsin Tester Jan 12 '16 at 10:34
  • In that case the "child user" needs Write, Read and Share access to the entity with ObjectTypeCode 10048. – Henrik H Jan 12 '16 at 11:27
  • the user already have these rights I am just sharing records with them – Mohsin Tester Jan 12 '16 at 11:35

0 Answers0