4

Listing all the users in the system, I noticed that some of them were system users and didn't have e.g. working hours at all. At the moment, I just list them and exclude from my loop my it's a Q&D approach and I prefer to do it right.

I haven't found any specific information on the systemuser entity that'd tell me if a certain one is a real profile (i.e. created in the Office 365 portal) or one that's provided my MS by default.

The Q&D code is as follows.

QueryExpression userQuery = new QueryExpression { EntityName = "systemuser", ... };
IEnumerable<Entity> users = service.RetrieveMultiple(userQuery).Entities;

IEnumerable<String> automatics = new[] { "INTEGRATION", "Support User", "SYSTEM" };
  foreach (Entity user in users.Where(element
    => !automatics.Contains(element.GetAttributeValue<String>("fullname")))) { ... }

Second best solution, if there's no way to determine who's on the automatics list and who's a real dude, is to make an exhaustive comprehensive list of exceptions. Once again, my google-fu failed me, as I haven't found any documentation on the full list of automatically created instances of the entity systemuser.

4

1 回答 1

2

An approach would be checking the CreatedBy field; which is NULL for users SYSTEM and INTEGRATION. This field is also NULL for the CRM administrator user, so you should consider excluding the admin user if it is actively being used by a human.

FilterExpression humanFilter = new FilterExpression();
humanFilter.AddCondition(new ConditionExpression("createdby", ConditionOperator.NotNull));

if (retrieveAdminUser)
{
  humanFilter.FilterOperator = LogicalOperator.Or;
  humanFilter.AddCondition(
    new ConditionExpression("domainname", ConditionOperator.Equal, "admin@crm"));
}

userQuery.Criteria.AddFilter(humanFilter);
于 2015-07-02T11:42:42.897 回答