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

Announcements

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans