Saturday 31 October 2015

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

No comments:

Post a Comment