Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Nested Query Expression

Posted on by 1,695

CRM2016 On-premises

I am trying to retrieve new_transactionsetid from new_transactionsets. Currently I have the following Query Expression

                    Dim LookupTransactionSet As QueryExpression = New QueryExpression With {.EntityName = "new_transactionsets", .ColumnSet = New ColumnSet("new_transactionsetsid"), .Criteria = New FilterExpression()}
                    LookupTransactionSet.Criteria.AddCondition("new_fileserial", ConditionOperator.EndsWith, _str_serialnumber)
                    LookupTransactionSet.Criteria.AddCondition("new_creditdebitdate", ConditionOperator.Equal, _clearedfundsdate)
                    LookupTransactionSet.Criteria.AddCondition("new_transactioncount", ConditionOperator.Equal, _fileCount)
                    LookupTransactionSet.Criteria.AddCondition("new_submissionvalue", ConditionOperator.Equal, _fileTotal)
                    Dim TransactionSetCollection As EntityCollection = service.RetrieveMultiple(LookupTransactionSet)


  new_transactiosets has a lookup field to new_originatingaccounts.

new_originatingaccounts has a field new_sun . I need to add another condition to my Query  new_originatingaccounts.new_sun = "xxxxxx"

Is this possible to in effect create a join as you would in a SQL Query ?

*This post is locked for comments

  • Verified answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Nested Query Expression

    Hi PeteN,

    You can use linked entities in the query expression. 

    LinkEntity linkEntity1 = new LinkEntity();
    linkEntity1.JoinOperator = JoinOperator.Natural;
    linkEntity1.LinkFromEntityName = "new_transactionsets";
    linkEntity1.LinkFromAttributeName = "new_orginatingaccounts";
    linkEntity1.LinkToEntityName = "account"; // Logical Name of the lookup entity new_originating accounts points to
    linkEntity1.LinkToAttributeName = "accountid"; // Primary key of the lookup entity
    
    linkEntity1.LinkCriteria = new FilterExpression();
    linkEntity1.LinkCriteria.FilterOperator = LogicalOperator.And;
    
    ConditionExpression condition1 = new ConditionExpression();
    condition1.AttributeName = "new_sun";
    condition1.Operator = ConditionOperator.Equal;
    condition1.Values = new object[] { "xxxxxxx" };
    
    linkEntity1.LinkCriteria.Conditions = new ConditionExpression[] { condition1 };

    LookupTransactionSet.LinkEntities = new LinkEntity[] { linkEntity1 };

    See: https://nishantrana.me/2007/11/02/link-entity-query-expression-and-fetchxml-wizard/

    Hope this helps.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans