Code to check if the user is a team member in CRM 2011/2013/2015

Hi,
 
Today we got a requirement to check if the user is a member of particular team and do some operation based on that.
 
Here is the C# code to check the user is a team member of the team.
 
public static bool CheckTeamMember(Guid guidTeam, Guid guidUser, IOrganizationService iService)
{
        QueryExpression objQueryExp = new QueryExpression(“team”);
        objQueryExp.ColumnSet = new ColumnSet(true);
        objQueryExp.Criteria.AddCondition(new ConditionExpression(“teamid”, ConditionOperator.Equal, guidTeam));
        LinkEntity lnkEntity = objQueryExp.AddLink(“teammembership”, “teamid”, “teamid”);
        lnkEntity.LinkCriteria.AddCondition(new ConditionExpression(“systemuserid”, ConditionOperator.Equal, guidUser));
        EntityCollection entColResults = iService.RetrieveMultiple(objQueryExp);
        if (entColResults.Entities.Count > 0)
        {
             return true;
        }
        else
        {
             return false;
        }
}
 
Hope this helps.
 

Happy CRM’ing
Gopinath

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 )

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