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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Query expression using customerid

(0) ShareShare
ReportReport
Posted on by 2

I need to write a query expression using customerid but the below query is throwing format exception. Please help

QueryExpression query = new QueryExpression("opportunity");
Guid contactid = new Guid("23E62DCE-F154-E843-814K-005056BB4062");
query.Criteria.AddCondition("customerid",ConditionOperator.Equal,new EntityReference("contact",contactid));
EntityCollection result = _orgService.RetrieveMultiple(query);

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    Try with this , replace column name which you want to retrieve.

    Guid contactid = new Guid("23E62DCE-F154-E843-814K-005056BB4062");

    ConditionExpression condition1 = new ConditionExpression();

    condition1.AttributeName = "customerid";

    condition1.Operator = ConditionOperator.Equal;

    condition1.Values.Add(contactid);            

    FilterExpression filter1 = new FilterExpression();

    filter1.Conditions.Add(condition1);

    QueryExpression query = new QueryExpression("opportunity");

    query.ColumnSet.AddColumns("column1", "column2"); // Replace column name .

    query.Criteria.AddFilter(filter1);

    EntityCollection result1 = _orgService.RetrieveMultiple(query);

  • ashlega Profile Picture
    34,477 on at

    I don't think you need to pass EntityReference - just pass the Guid to your condition

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    You just need to use like below

    query.Criteria.AddCondition("customerid",ConditionOperator.Equal,contactid);

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at

    Hi Lathin,

    You dont need to pass the Entity reference in the above code,

    Please try with below code,

    QueryExpression query = new QueryExpression("opportunity");

    Guid contactid = new Guid("23E62DCE-F154-E843-814K-005056BB4062");

    query.Criteria.AddCondition("customerid",ConditionOperator.Equal,contactid);

    EntityCollection result = _orgService.RetrieveMultiple(query);

    Best Regards,

    Shahbaaz

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans