Wednesday, October 27, 2010

How to Obtain all records shared for a particular user?

Have you ever tried to retrieve all the records (all accounts/opportunities) shared to a particular user?

I found one of a user asking the same in CRM development forum. Refer here for the thread.

As you are all aware CrmService exposes RetrieveSharedPrincipalsAndAccess message for retrieving the access rights.

Limitation: The above approach can be only used for a specified entity instance (for a particular record defined by its GUID).

What if the user wants to obtain the result of all the record (accounts/opportunity/...) shared to a particular user?

There is not any special message exposed by CrmService as like RetrieveSharedPrincipalsAndAccess to get it done. Hence we are on own now.

The immediate workaround that striked me is CrmService.Fetch method.

Sharing related infromations are stored in PrincipalObjectAcces.
Even though principalObjectAcces is not exposed outside, fetchXML wont restrict in using it. Taking this as an advantage you can obtain our required result using fetch method

Come lets try to Obtain all the Opportunity shared for a particular user.

Inputs:
1. Opportunity Object Type Code(3)
2.SystemUser (to which the record is shared)



Output resultSet:


Happy Coding !!!

2 comments:

  1. Vinoth, this is an excellent post for this behavior. Even though I know this behavior was discovered by somebody else (as I linked in the recent thread where we discussed it), I'm in awe of your technical expertise with CRM and find myself learning from your contributions to the CRM community.

    I have a personal question to ask of you, so I hope you'll send me an email to the address listed in my blogger profile.

    ReplyDelete
  2. Hi DavidBerry

    Thanks for your comments and encouragement.

    Thanks & Regards
    Vinoth B

    ReplyDelete