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.