locked
Retrieve all shared opportunities for a user? RRS feed

  • Question

  • I can't seem to find the right CrmService class to go about retrieving all shared records based on a user's ID and entity name.  For example, get all opportunites that are shared with the user bob.  Please help..Thanks!

    Tuesday, October 26, 2010 9:34 PM

Answers

  • Yes. As DavidBerry and Pogo69 say you can retrieve access rights for the specified entity instance (for a single records)

    But in your case CrmService.Fetch method can provide you a workaround.

    Even though principalObjectAcces is not exposed outside, fetchXML wont restrict in using it. Taking this as an advantage you can obtain your required result using fetch method

    E.g The below code retrives all the opportunitites shared for a particular user.

    Inputs: Opportunity Object Type Code (3) & SystemUser (to which the user is shared - in your case user bob)

    string fetchxml = @"
    <fetch mapping='logical'>
     <entity name='principalobjectaccess'> 
     <filter type='and'>
     <condition attribute = 'objecttypecode' operator='eq' value='3'/>
     <condition attribute = 'principalid' operator='eq' value='A0D54C73-B634-DE11-9B74-0003FF18DEBC'/>
     </filter>
     <link-entity name='opportunity' from='opportunityid' to='objectid'>
     <attribute name='name'/>
     </link-entity>
     </entity>
    </fetch>";
    
    String result = CrmService.Fetch(fetchxml); 
    
    Wednesday, October 27, 2010 9:21 AM
  • As far as I know, pogo69 is right.  There is no exposed method from the CRM SOAP API that enumerates or retrieves lists of shared records.  However, if you impersonate the user when attaching to the CRM Service, you'll be able to retrieve only those records for which security privileges are granted (either by Role or by Share).  You may be able to utilize that behavior with a mask that filters out records for which privileges are granted by Role to discover the records that would presumably be shared.

    Also, you can probe the PrincipleObjectAccess table in SQL.  Be careful, however, there are no established views to that table, and updates to it directly are unsupported by Microsoft.


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    • Marked as answer by 600rr Wednesday, October 27, 2010 3:05 PM
    Tuesday, October 26, 2010 10:56 PM
    Moderator

All replies

  • I can't find it either; the closest I can see in the SDK is RetrieveSharedPrincipalsAndAccess, which requires a target (single entity instance) and returns those principals with which the entity instance is shared.  Very inefficient for your purposes.

    What are you trying to achieve?


    --pogo (pat)
    Tuesday, October 26, 2010 10:34 PM
  • As far as I know, pogo69 is right.  There is no exposed method from the CRM SOAP API that enumerates or retrieves lists of shared records.  However, if you impersonate the user when attaching to the CRM Service, you'll be able to retrieve only those records for which security privileges are granted (either by Role or by Share).  You may be able to utilize that behavior with a mask that filters out records for which privileges are granted by Role to discover the records that would presumably be shared.

    Also, you can probe the PrincipleObjectAccess table in SQL.  Be careful, however, there are no established views to that table, and updates to it directly are unsupported by Microsoft.


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    • Marked as answer by 600rr Wednesday, October 27, 2010 3:05 PM
    Tuesday, October 26, 2010 10:56 PM
    Moderator
  • Yes. As DavidBerry and Pogo69 say you can retrieve access rights for the specified entity instance (for a single records)

    But in your case CrmService.Fetch method can provide you a workaround.

    Even though principalObjectAcces is not exposed outside, fetchXML wont restrict in using it. Taking this as an advantage you can obtain your required result using fetch method

    E.g The below code retrives all the opportunitites shared for a particular user.

    Inputs: Opportunity Object Type Code (3) & SystemUser (to which the user is shared - in your case user bob)

    string fetchxml = @"
    <fetch mapping='logical'>
     <entity name='principalobjectaccess'> 
     <filter type='and'>
     <condition attribute = 'objecttypecode' operator='eq' value='3'/>
     <condition attribute = 'principalid' operator='eq' value='A0D54C73-B634-DE11-9B74-0003FF18DEBC'/>
     </filter>
     <link-entity name='opportunity' from='opportunityid' to='objectid'>
     <attribute name='name'/>
     </link-entity>
     </entity>
    </fetch>";
    
    String result = CrmService.Fetch(fetchxml); 
    
    Wednesday, October 27, 2010 9:21 AM
  • Does that actually work, Vinoth?  If so, it's not only awesome, but I hope you have a blog where you've posted it (or discovered it), because I'd sure like to have a link.
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Wednesday, October 27, 2010 4:41 PM
    Moderator
  • It appears, Vinoth, that you are indeed correct about using FetchXML to access shared records .  I wouldn't have expected that, with the absence of a "principleobjectaccess" entity in the Metadata Browser.

    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Thursday, October 28, 2010 3:23 AM
    Moderator
  • Does that actually work, Vinoth?  If so, it's not only awesome, but I hope you have a blog where you've posted it (or discovered it), because I'd sure like to have a link.

     

    Hi DavidBerry

    It works. I tired, and found that it worked. 

    It would be a blessing for me to have it linked :)

     

    Thanks & Regards

    Vinoth

     

    Thursday, October 28, 2010 5:15 AM