Thursday 3 December 2015

Retrieve Access Team Members using FetchXML in CRM 2013/2015

Hi,

Today we got a requirement to fetch the users who are added on the Access Team of the record and do some operation.

Here is the Fetch XML to retrieve the users that were added to access team.

I was using for Order entity. If you are using for any other entity, you need to change the entity name in the 2nd line and ID schema name in the 4th line of the Fetch Xand pass record Id in the filter condition.

public static void GetAccessTeamMembers(IOrganizationService iService)
{
      string strFetchXML = @"<fetch>
                             <entity name='salesorder' >
                               <attribute name='name' />
                                   <link-entity name='principalobjectaccess' from='objectid' to='salesorderid' 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' >
                                          <attribute name='teamtemplatename' />
                                        </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' />
                                         </link-entity>
                                       </link-entity>
                                      </link-entity>
                                      <filter type='and'>
                                       <condition attribute='objectid' operator='eq' value='GUID_OF_THE_RECORD' />
                                        </filter>  
                                    </link-entity>
                                  </entity>
                                </fetch>";

      EntityCollection entColAccessTeamMembers = iService.RetrieveMultiple(new FetchExpression(strFetchXML));
}

Hope this helps.

--
Happy CRM'ing

Gopinath

No comments:

Post a Comment