Retrieve crm users based on Team

If you are looking to get all crm users based on the teamid then this post is for you. You can use below code to retrieve users:

private EntityCollection GetAllTeamUsers(IOrganizationService _CrmService,Guid TeamID)
{
//Create query expression
QueryExpression _Query = new QueryExpression();
_Query.EntityName = "systemuser";
_Query.ColumnSet = new ColumnSet(true);
_Query.ColumnSet.AddColumn("systemuserid");
_Query.LinkEntities.Add(new LinkEntity
{
LinkFromEntityName = "systemuser",
LinkToEntityName = "teammembership",
LinkFromAttributeName = "systemuserid",
LinkToAttributeName = "systemuserid",
LinkCriteria =
new FilterExpression
{
Conditions ={
new ConditionExpression("teamid",ConditionOperator.Equal,TeamID)
}
}
});
return _CrmService.RetrieveMultiple(_Query);
}

Enjoy !!!

Leave a Reply

Your email address will not be published. Required fields are marked *