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);
_Query.LinkEntities.Add(_LinkEntity);
_Teammembers = _Service.RetrieveMultiple(_Query);
return _Teammembers;
}

Enjoy !!!

Advertisements

Leave a comment

Filed under MS CRM 2011

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s