Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

SQL to FetxhXML Conversion for linked-entity attribute is null

Posted on by 685

Hi,

I have the following SQL which works fine:

SELECT DISTINCT
	fullname, 
	cdi_postedsubscription.cdi_postedsubscriptionid
FROM contact
LEFT OUTER JOIN cdi_postedsubscription cdi_postedsubscription 
	ON cdi_postedsubscription.cdi_contactid = contact.contactid
WHERE contact.statecode = 0
AND cdi_postedsubscriptionid is NULL
ORDER BY fullname

when I try to convert this to FetchXML where will I add the following line?

AND cdi_postedsubscriptionid is NULL

If I add it in the on statement of the link-entity as follows then it returns an incorrect result:

If I add it in the on statement of the link-entity as follows then it returns an incorrect result:

<fetch mapping="logical" distinct="true" version="1.0">
  <entity name="contact">
    <attribute name="fullname" />
    <order attribute="fullname" />
    <filter>
      <condition attribute="statecode" operator="eq" value="0" />
    </filter>
    <link-entity name="cdi_postedsubscription" from="cdi_contactid" to="contactid" alias="cdi_postedsubscription" link-type="outer">
      <attribute name="cdi_postedsubscriptionid" />
      <filter>
        <condition attribute="cdi_postedsubscriptionid" operator="null" />
      </filter>
    </link-entity>
  </entity>
</fetch>

If I add it to the filter of the contact as follows then it displays an error saying cdi_postedsubscriptionid does not exist in contact entity:

<fetch mapping="logical" distinct="true" version="1.0">
  <entity name="contact">
    <attribute name="fullname" />
    <order attribute="fullname" />
    <filter>
      <condition attribute="statecode" operator="eq" value="0" />
      <condition attribute="cdi_postedsubscriptionid" operator="null" />
    </filter>
    <link-entity name="cdi_postedsubscription" from="cdi_contactid" to="contactid" alias="cdi_postedsubscription" link-type="outer">
      <attribute name="cdi_postedsubscriptionid" />
    </link-entity>
  </entity>
</fetch>

Thanks for any pointers

Richard

*This post is locked for comments

  • crmrsw15 Profile Picture
    crmrsw15 685 on at
    RE: SQL to FetxhXML Conversion for linked-entity attribute is null

    oh yes, sorry i wasnt adding entity into the condition!

    Thanks Andrew!

  • crmrsw15 Profile Picture
    crmrsw15 685 on at
    RE: SQL to FetxhXML Conversion for linked-entity attribute is null

    Thanks Andrew, that throws the same error 'contact entity doesn't contain attribute with name = cdi_postedsubscriptionid'

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: SQL to FetxhXML Conversion for linked-entity attribute is null

    Hello, try following:

    <fetch mapping="logical" distinct="true" version="1.0">
      <entity name="contact">
        <attribute name="fullname" />
        <order attribute="fullname" />
        <filter>
          <condition attribute="statecode" operator="eq" value="0" />
          <condition entity="cdi_postedsubscription" attribute="cdi_postedsubscriptionid" operator="null" />
        </filter>
        <link-entity name="cdi_postedsubscription" from="cdi_contactid" to="contactid" alias="cdi_postedsubscription" link-type="outer">
          <attribute name="cdi_postedsubscriptionid" />
        </link-entity>
      </entity>
    </fetch>


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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans