Sample code to check if User is a member of a team C# CRM 2011/2013/2015

Sharing sample code to check if a user belongs to a team or not


public static bool IsTeamMember(Guid teamID, Guid userID, IOrganizationService service)
{
QueryExpression query = new QueryExpression("team");
query.ColumnSet = new ColumnSet(true);
query.Criteria.AddCondition(new ConditionExpression("teamid", ConditionOperator.Equal, teamID));
LinkEntity link = query.AddLink("teammembership", "teamid", "teamid");
link.LinkCriteria.AddCondition(new ConditionExpression("systemuserid", ConditionOperator.Equal, userID));
var results = service.RetrieveMultiple(query);

if (results.Entities.Count > 0)
{
return true;
}
else
{
return false;
}
}

Hope it helps.


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

2 thoughts on “Sample code to check if User is a member of a team C# CRM 2011/2013/2015”

Share your thoughts

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