Skip to content

[BUG] Wrong FetchXML generated #738

Description

@AgileXRM

Describe the bug
A particular SQL query returns correct records but is not correctly converted to FetchXML.

To Reproduce

  1. Create two new Lookups in Account table to Contact: Billing Contact and Technical Contact
  2. Create Account1 record with 4 child Contact Records
  3. Set Contact1 as Primary Contact in Account1
  4. Set Contact 2 as Billing Contact
  5. Set Contact3 as Technical Contact
  6. Enter below SQL and execute
  7. Notice Contact 1, 2 and 3 returned correctly and not Contact 4
  8. Click Convert to FetchXML
  9. Run this in FetchXML Builder, and returns wrong result
SELECT  contact.fullname                  
FROM     contact, account
WHERE
   (contact.contactid = account.primarycontactid  OR
   contact.contactid = account.new_billingcontact  OR
   contact.contactid = account.new_technicalcontact)  AND
   contact.parentcustomerid = account.accountid

Expected behavior
The FetchXML should be:

<fetch>
  <entity name="contact">
    <attribute name="fullname" />
    <link-entity name="account" to="parentcustomerid" from="accountid" alias="account" link-type="inner" />
    <link-entity name="account" from="primarycontactid" to="contactid" alias="acc_primary" link-type="outer" />
    <link-entity name="account" from="new_billingcontact" to="contactid" alias="acc_billing" link-type="outer" />
    <link-entity name="account" from="new_technicalcontact" to="contactid" alias="acc_technical" link-type="outer" />
    <filter type="or">
      <condition entityname="acc_primary" attribute="primarycontactid" operator="not-null" />
      <condition entityname="acc_billing" attribute="new_billingcontact" operator="not-null" />
      <condition entityname="acc_technical" attribute="new_technicalcontact" operator="not-null" />
    </filter>
    <order attribute="fullname" />
  </entity>
</fetch>

Environment (please complete the following information):

  • SQL 4 CDS edition: XrmToolBox
  • Results of SELECT @@VERSION:
    Microsoft Dataverse - 9.2.25124.197
    SQL 4 CDS - 10.3.0.0
    feb. 04 2026 16:21:48
    Copyright © 2020 - 2025 Mark Carrington

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions