Home > CRM, Uncategorized > Retrieve Members of a Records Access Team and migrate Access Teams between Organizations

Retrieve Members of a Records Access Team and migrate Access Teams between Organizations

Most of you know that an Access team owns no records and has no security roles assigned to it.

Records will be shared with an Access team, and the team is granted access rights on records such as Read, Write and Append.

OOB Opportunity Access Team

By default, we would get one OOB Opportunity Access Team and we can enable “Access Team” for required entities by selecting “Access Teams” option in entity customization’s.

Enable Access Team

We can add “Access Team” to the form’s sub grid and keep adding the users

Add Access Team Sub Grid.PNG

Below is the sample code to retrieve the members of Access Team for a record (i.e., Opportunity in this case)

Code Snippet:

Private void GetUsersFromOpportunitySalesTeam(IOrganizationService service, Guid opportunityId, Guid teamTemplateId)        {

var fetchUsersFromSalesTeam = @”<fetch>

<entity name=’opportunity’ > <attribute name=’name’ />

<filter type=’and’>

<condition attribute=’opportunityid’ operator=’eq’ value='” + opportunityId + @”‘ />       </filter>

<link-entity name=’principalobjectaccess’ from=’objectid’ to=’opportunityid’ link-type=’inner’ alias=’poa’ >

<attribute name=’objectid’ alias=’objectid’ />

<link-entity name=’team’ from=’teamid’ to=’principalid’ link-type=’inner’ >

<link-entity name=’teamtemplate’ from=’teamtemplateid’ to=’teamtemplateid’ >

<filter type=’and’>

<condition attribute=’teamtemplateid’ operator=’eq’ value='” + teamTemplateId + @”‘/> </filter>

</link-entity>

<link-entity name=’teammembership’ from=’teamid’ to=’teamid’ link-type=’inner’ intersect=’true’ >

<link-entity name=’systemuser’ from=’systemuserid’ to=’systemuserid’ link-type=’inner’ >

<attribute name=’fullname’ /> <attribute name=’systemuserid’ />

</link-entity>   </link-entity> </link-entity>  </link-entity>   </entity>

</fetch>”;

var teamMembers = service.RetrieveMultiple(new FetchExpression(fetchUsersFromSalesTeam));

// Retrieve User Guids

if (teamMembers!= null && teamMembers.Entities.Count > 0) {

foreach (var teamMember in teamMembers.Entities){

if (teamMember.Attributes.Contains(“systemuser5.systemuserid”) && teamMember.Attributes[“systemuser5.systemuserid”] != null) {

Guid userId = new Guid(((AliasedValue) teamMember.Attributes[“systemuser5.systemuserid”]).Value.ToString());

}

}

}

How to get the “Access Team Id” (i.e.,teamTemplateId)

  • Make a retrieve call “teamtemplate” entity and retrieve the Id by Name field (i.e., Opportunity Sales Team Template)
  • Or you can get the GUID from URL of “Access Team Template”

Points to ponder:

  • “Access Team” is not a solution aware component and cannot be added to the Solution to move across the organizations.
  • If you have an Opportunity Access Team sub grid on Account form and if you move the customization’s from Dev to Test organizations, the sub grids will break, if you cannot maintain the “Access Team” with same Id
  • To move Access Teams between Organizations with same Guid’s, below are couple of ways
    • A console application (Link)
    • XRMToolbox Plug-in (Link)

🙂

Advertisement
  1. February 1, 2019 at 3:01 PM

    Hi Rajeev,

    This is great! I wanted to if you managed to do the same using Web Api.
    I cant seem to find a way.

  2. Prakhar Mathur
    February 2, 2019 at 12:32 PM

    Hi Rajeev,

    Thanks for sharing the information, it is really helpful.
    How can we manage to do this using WebAPI. I am trying to pass the fetchxml (which is the same query mentioned above) in Xrm.WebApi.retrieveMultipleRecords(entityLogicalName, fetchxml) but no luck.

    • September 26, 2019 at 9:08 AM

      Somehow I missed this question. You might want to use ‘Predefined Query’ option in Rest Builder. Let me know if you still facing issues.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: