Fetch team members for selected Team

I got one requirement to get all team members based on team, so I thought to share code here so that it can help other crm developers. you can use below code

private EntityCollection GetTeammembers(IOrganizationService _iService,Guid TeamID)
EntityCollection _Teammembers = null;
Guid _UserId = Guid.Empty;
EntityCollection col = new EntityCollection();
QueryExpression _Query = new QueryExpression();
_Query.EntityName = “systemuser”;
_Query.ColumnSet = new ColumnSet(new string[] { “systemuserid”, “firstname” });
LinkEntity _LinkEntity = new LinkEntity();
_LinkEntity.LinkFromAttributeName = “systemuserid”;
_LinkEntity.LinkToAttributeName = “systemuserid”;
_LinkEntity.LinkFromEntityName = “systemuser”;
_LinkEntity.LinkToEntityName = “teammembership”;
_LinkEntity.JoinOperator = JoinOperator.Natural;
_LinkEntity.LinkCriteria = new FilterExpression();
_LinkEntity.LinkCriteria.AddCondition(“teamid”, ConditionOperator.Equal, TeamID);
_Teammembers = _Service.RetrieveMultiple(_Query);
return _Teammembers;

Enjoy !!!

Leave a Reply