Retrieve crm user based on Team ID

If you are looking to get all crm users based on the teamid then this post is for you. You can use below code to retrieve users:

 
        private EntityCollection GetAllTeamUsers(IOrganizationService _CrmService,Guid TeamID)
        {
                //Create query expression
                QueryExpression _Query = new QueryExpression();
                _Query.EntityName = "systemuser";
                _Query.ColumnSet = new ColumnSet(true);
                _Query.ColumnSet.AddColumn("systemuserid");
                _Query.LinkEntities.Add(new LinkEntity
                        {
                            LinkFromEntityName = "systemuser",
                            LinkToEntityName = "teammembership",
                            LinkFromAttributeName = "systemuserid",
                            LinkToAttributeName = "systemuserid",
                            LinkCriteria =
                            new FilterExpression
                            {
                                Conditions ={
                            new ConditionExpression("teamid",ConditionOperator.Equal,TeamID)
                                            }
                            }
                       });
                return _CrmService.RetrieveMultiple(_Query);
         }

Hope it will help someone !!!

Ebook Download
View all
Learn
View all