Being reasonably new to the CRM SDK I needed a method to retrieve all users from the system. This was needed as I was doing a piece of work to replicate permissions between CRM business units and SharePoint.
Retrieving all users via a query expression turned out to be quite simple…
private static EntityCollection RetrieveAllUsers(IOrganizationService service) { QueryExpression query = new QueryExpression { EntityName = "systemuser", ColumnSet = new ColumnSet(true), Criteria = { Conditions = { new ConditionExpression { AttributeName = "businessunitid", Operator = ConditionOperator.NotNull } } } }; return service.RetrieveMultiple(query); }
The EntityCollection returns a number of useful attributes, such as the users’ business unit, whether they have a valid licence, account status and so on.
Advertisements