Hi,
I'm deriving new workflow step from an existing Codeplex solution (https://msdyncrmworkflowtools.codeplex.com) step "Update Child Records"). I'm trying to add possibility of filtering child entities that will be updated.
Therefore I added three new parameters for condition attribute, operator and value. I created new function UpdateChildRecordsConditional (derivation from UpdateChildRecords), with three parameters above and with additional part that processes three new parameters.
My main changes are marked red bellow in source code.
It works OK when I specify an ConditionOperator that requires vaule (e.g. attribute="name"; operator="Equal"; value = "something").
!!!! But, when I specify condition that doesn't require value (e.g. attribute="name"; operator="NotNull"), retrieveMultiple raises the exception "Condition operator 'NotNull' requires that no values are set. Values.Length: 1".
I checked it in CRM 2016 on premise, online and Dynamics 365. Of course I checked the Query.Criteria.Values for the last part and it contains 0 values. I also debugged it and verified that red lines are executed.
Here is the source code(this code might not be valid for some of attribute types).
///////// Code Begin
public void UpdateChildRecordsConditional(string relationshipName, string parentEntityType, string parentEntityId
, string parentFieldNameToUpdate, string setValueToUpdate, string childFieldNameToUpdate
, string conditionAttribute, string conditionOperator, string conditionValue)
{
// here comes original code
//....
// I added/changed this:
QueryExpression query = new QueryExpression
{
EntityName = childEntityType,
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression
{
AttributeName = "statecode",
Operator = ConditionOperator.Equal,
Values = {0}
}
,new ConditionExpression
{
AttributeName = childFieldNameToUpdate,
Operator = ConditionOperator.NotEqual,
Values = {valueToUpdate}
}
, new ConditionExpression
{
AttributeName = childEntityFieldName,
Operator = ConditionOperator.Equal,
Values = {parentEntityId}
}
, new ConditionExpression
{
AttributeName = conditionAttribute,
Operator = co,
Values = {conditionValue}
}
}
}
};
ConditionOperator co = (ConditionOperator)Enum.Parse(typeof(ConditionOperator), conditionOperator);
if (conditionAttribute != null && conditionAttribute != "")
{
if (conditionValue != null && conditionValue != "")
{
query.Criteria.AddCondition(new ConditionExpression
{
AttributeName = conditionAttribute,
Operator = co,
Values = { conditionValue }
});
}
else
{
query.Criteria.AddCondition(new ConditionExpression(conditionAttribute, co));
// same with query.Criteria.AddCondition(new ConditionExpression(conditionAttribute, co, null));
}
}
EntityCollection retrieved = service.RetrieveMultiple(query);
...
}
////////// Code End
*This post is locked for comments