Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Query expression to retrieve record

(0) ShareShare
ReportReport
Posted on by 255

Hi All,

I want to write plugin code where i need to search for record of "Product" and assign it to lookup fields.

can you help me how to write code for this using query expression.

i have fetch number and client details only i need to search record in product entity based on these values 

can anybody tell me how to write a code for this.

scenario: if Number =123

Client=ABC

if (Product entity contains data matching with number=123 and client =ABC )

then assign id of this record to associated lookup.

  • Anas Rafik Profile Picture
    Anas Rafik 363 on at
    RE: Query expression to retrieve record

    Try this:

    ConditionExpression condition1 = new ConditionExpression();  
    condition1.AttributeName = "new_client";  
    condition1.Operator = ConditionOperator.Equal;  
    condition1.Values.Add(yourClient.id);              
    
    ConditionExpression condition2 = new ConditionExpression();  
    condition2.AttributeName = "new_number";  
    condition2.Operator = ConditionOperator.Equal;  
    condition2.Values.Add(123);
    
    FilterExpression filter1 = new FilterExpression();  
    filter1.Conditions.Add(condition1);
    filter1.Conditions.Add(condition2);
      
    QueryExpression query = new QueryExpression("product");  
    query.ColumnSet.AddColumns("name", "productnumber");  
    query.Criteria.AddFilter(filter1);  
      
    EntityCollection result1 = _serviceProxy.RetrieveMultiple(query);  

  • Mona Chavan Profile Picture
    Mona Chavan 255 on at
    RE: Query expression to retrieve record

    can you please share code please.

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,052 on at
    RE: Query expression to retrieve record

    Hi

    You could try the following

    Define your query first in Advance Find, once you are happy with the query, download the FETCH XML and paste it into FetchXML Builder  XrmToolBox plugin to get the QueryExpression c# code

    5822.ScreenClip-_5B00_241_5D00_.png

    2185.ScreenClip-_5B00_246_5D00_.png

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans