I'm trying to retrieve user with specific role from MS CRM 2011 business unit via C# plugin, however I stuck in composing right query for this. Roles linked to users via N:N
relationship and I'm struggling to find example query for this case.
For now I came up with following:
var entity = organizationService.Retrieve(entityName, entityId, new ColumnSet(new string[] { "new_unit" }));
if (entity.Attributes.Keys.Contains("new_unit"))
{
QueryExpression query = new QueryExpression("systemuser");
query.ColumnSet = new ColumnSet(new string[] { "systemuserid" });
query.Distinct = true;
query.Criteria = new FilterExpression();
query.Criteria.AddCondition("businessunitid", ConditionOperator.Equal, ((EntityReference)entity.Attributes["new_unit"]).Id);
}
I not sure to which entity I need to link systemuser
and how, to achieve the goal retrieve user with specific role and business unit.
I can get easily the name of the role or it's Guid
, but what I should do next with it?