Dynamics CRM Query Expression filter or condition for two related objects
I am currently trying to restore all users on the system that are either assigned to a specific security role , or assigned to a team that has a security role. when building the query, it seems like they are only filtering them on condition and
when writing the query this way:
QueryExpression RolesQuery = new QueryExpression
{
EntityName = "systemuser",
ColumnSet = new ColumnSet("systemuserid"),
Distinct = true,
Criteria =
{
Filters =
{
new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("isdisabled", ConditionOperator.Equal, "0")
}
}
}
},
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName = "systemuser",
LinkToEntityName = "systemuserroles",
LinkFromAttributeName = "systemuserid",
LinkToAttributeName = "systemuserid",
LinkCriteria =
{
Filters =
{
new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("roleid", ConditionOperator.Equal, "00000000-0000-0000-0000-000000000000")
}
}
}
}
},
new LinkEntity
{
LinkFromEntityName = "systemuser",
LinkToEntityName = "teammembership",
LinkFromAttributeName = "systemuserid",
LinkToAttributeName = "systemuserid",
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName = "teammembership",
LinkToEntityName = "team",
LinkFromAttributeName = "teamid",
LinkToAttributeName = "teamid",
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName = "team",
LinkToEntityName = "teamroles",
LinkFromAttributeName = "teamid",
LinkToAttributeName = "teamid",
LinkCriteria =
{
Filters =
{
new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("roleid", ConditionOperator.Equal, "00000000-0000-0000-0000-000000000000")
}
}
}
}
}
}
}
}
}
}
};
My question is, is there a way to apply a filter or
to two related objects?
I found it work using two fetch expression queries, then merging the two results and doing a separate invoice, but I'm just wondering if there is a way to express the query to do this in a single query.
+3
source to share