Get members(Users) of a team

The method below will return you a list of users which are part of a team that will be received as parameter:

        public static List<Entity> GetTeamMembers(Guid teamID, IOrganizationService service)
            string fetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
                                  <entity name='systemuser'>
                                    <attribute name='systemuserid' />
                                    <order attribute='fullname' descending='false' />
                                    <link-entity name='teammembership' from='systemuserid' to='systemuserid' visible='false' intersect='true'>
                                      <link-entity name='team' from='teamid' to='teamid' alias='ab'>
                                        <filter type='and'>
                                          <condition attribute='teamid' operator='eq' uitype='team' value='{" + teamID + @"}' />
            var results = service.RetrieveMultiple(new FetchExpression(fetchXML)).Entities.ToList();
            return results;

Leave a Reply

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

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s