Sunday, February 6, 2011

Sharing Records in CRM Using DB Scripts

When you share a record with a team or a user do you know where it is stored in the database? The entity name is PrincipalObjectAccess. This is the entity which stores the shared information.

I have stated below the columns which will have to be populated in this table.

This field stores information regarding Team/User guid that the record will be shared with.

This field stores information regarding whether the record is shared with a team or a user.
Team – Value is 9
User – Value is 8

This field stores information regarding the record that is being shared with a user/team

This field stores information regarding the shared record entity type code.
e.g.:  account – 1
Contact – 2..etc…..

Type of share
e.g.: - read, write

These are the important fields to remember.

SQL script to do this is given below.

INSERT into PrincipalObjectAccess ( PrincipalId, PrincipalTypeCode, ObjectId, ObjectTypeCode, AccessRightsMask,
InheritedAccessRightsMask, ChangedOn)

Values (guid, 9,  @aID, (select objecttypecode from entity where logicalname ='account'), 786455, 0, GETDATE()


  1. Thank you.. This will helped me to find out which records are not shared out of 500000 records :-)


Retrieving Calendar of a Bookable Resource in Dynamics

There are occasions where we need to retrieve working days and working times of a resource in Dynamics grammatically. This is quite possible...