Get All users based on Business Unit -MS CRM 2011

If you are looking for a code to get all the users for a particular business unit, you can use below code

private EntityCollection RetrieveUserBasedOnBusinessUnit(IOrganizationService _CrmService,Guid BUId)
        {
            QueryExpression _Query = new QueryExpression
                   {
                       EntityName = “systemuser”,
                       ColumnSet = new ColumnSet(true),
                       Criteria =
                       {
                          Conditions =
                        {
                            new ConditionExpression
                            {
                                AttributeName=”businessunitid”,
                                Operator=ConditionOperator.Equal,
                                Values={BUId}

                            }
                        }
                       }
                   };
            return _CrmService.RetrieveMultiple(_Query);
        }
Enjoy !!!

Leave a Reply

Your email address will not be published. Required fields are marked *