web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Condition for attribute '<entity>.statecode': statecode values are expected to be passed as strings or int

(0) ShareShare
ReportReport
Posted on by 15

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

I have the same question (0)
  • Guido Preite Profile Picture
    54,086 Moderator on at

    it's strange, however try to create it with the direct constructor:

    query.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);

  • sbarrett Profile Picture
    15 on at

    Thanks for the reply. That produced the same result, unfortunately.

  • Guido Preite Profile Picture
    54,086 Moderator on at

    try to change the nuget package, it may be a bug of the version you are using

  • billwinder Profile Picture
    2 on at
    I am just wondering if you go to the bottom of this, I am experiencing the same issue. thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 74 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 31 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans