Hi,
I am trying figure out why I am getting the following error when trying build a condition to query an entity based on statecode
Condition for attribute '<entity>.statecode': statecode values are expected to be passed as strings or int
EntityCollection results;
QueryExpression query = new QueryExpression("xyz_entity");
query.ColumnSet.AddColumn("xyz_subject");
query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0));
results = crmConnection.RetrieveMultiple(query);
Console.WriteLine($"{results.Entities.Count} entities retrieved");
I don't know why it fails. I thought Active (0) and Inactive (1) were built in values and I have seen other examples of this very thing online.
When I replace the condition with the following it works.
query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, "Active"));
But I am hitting 2 different dynamic 365 CRMs with the existing code (...ConditionOperator.Equal, 0) and it works on one CRM but not the other. Also this pattern is used throughout the system so I don't want to have to change it. It feels like a set up/configuration issue on the other CRM, but I don't know what that might be
I can execute the query using Fetch XML without issue
string fetchXml =
@$"
";
results = crmConnection.RetrieveMultiple(new FetchExpression(fetchXml));
Console.WriteLine($"{results.Entities.Count} entities retrieved");
Any ideas why it might be failing on one CRM but working on the other?
I'd really appreciate any thoughts.
Thanks,
Seamus