Dynamics CRM 2011 Plugin How to get the team(s) a user belongs to

crm, dynamics-crm-2011, microsoft-dynamics

Solution

This was my final solution...

QueryExpression teamQuery = new QueryExpression("team");
ColumnSet teamColumnSet = new ColumnSet("name");

teamQuery.ColumnSet = teamColumnSet;
teamQuery.Criteria = new FilterExpression();
teamQuery.Criteria.FilterOperator = LogicalOperator.And;
teamQuery.Criteria.AddCondition("name", ConditionOperator.Equal, "Sales");
teamQuery.AddLink("teammembership", "teamid", "teamid").AddLink ("systemuser", "systemuserid", "systemuserid").LinkCriteria.AddCondition("systemuserid", ConditionOperator.Equal, salesRepGuid);

 EntityCollection teamDetail = service.RetrieveMultiple(teamQuery);

Gary

Problem

I have a requirement to check and see if a user is on a specific team. I'm assuming that I have to start at the team, but I'm not really sure about that. It would easier to just look and see all the teams a user belongs to. Does anyone have an example of using a N:N relationship in a plugin? Here is the code I have so far... ``` // Set the properties of the QueryExpression object. teamQuery.EntityName = "team"; teamQuery.AddAttributeValue("name", "Team"); teamQuery.ColumnSet = teamColumnSet; EntityCollection teamDetail = service.RetrieveMultiple(teamQuery); foreach (var teamDetail in teamDetail.Entities) { teamGuid = teamDetail.Id; } ``` Thank you for the help!! Gary

Original source