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 :
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

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans