Wednesday, 1 March 2023

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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;
}
}

No comments:

Post a Comment

How to Trigger a Microsoft Flow from a Custom Button in Dynamics 365

  When using Microsoft Flow the out-of-the-box button is nested under the ‘Flow’ section and is not easy to find nor is it customizable. Tri...