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)

fetchXML get account and relevant cases

(0) ShareShare
ReportReport
Posted on by 2,510

Hi, I have account and case entity, they are associated by account ID. In case entity, it mapped to customerid lookup field. My question is how can I left join case entity through account entity, since there is no account ID attribute in case entity.

sql query:

select a.LegalName,a.RegistrationID,a.Address1_PostalCode,a.im_OrganizationID,c.[Resolution Date] from [001 Accounts] a
left join dbo.[013Case] c on a.im_OrganizationID = c.[ACCOUNT ID]
where c.[ACCOUNT ID]='11738'


fetchXML:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="account">
    <attribute name="new_registrationid" />
    <attribute name="new_legalname" />
    <attribute name="new_im_organizationid" />
    <attribute name="address1_postalcode" />
    <attribute name="address1_primarycontactname" />
    <attribute name="accountid" />
    <link-entity name="incident" from="dev_accountid" to="im_OrganizationID" alias="ab" link-type="outer">
    	<attribute name="Resolution Date"/>
    </link-entity>
    <filter type="and">
    	<condition entityname="ab" attribute="dev_accountid" operator="eq" value="11738"/>
    </filter>
  </entity>
</fetch>


*This post is locked for comments

I have the same question (0)
  • Thomas David Dayman Profile Picture
    11,323 on at

    Are you trying to get all cases related to a certain customer?

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    It should look like following:

    <fetch>

     <entity name="account" >

       <link-entity name="incident" from="customerid" to="accountid" />

     </entity>

    </fetch>

    Just curious- why don't you want to use Advanced Find to build and test it instead?

  • sdnd2000 Profile Picture
    2,510 on at

    Sorry, I am customizing it. Is it able to get primary contact? it looks like only primary contactid

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Primary Contact for Account or for Case because both have that field?

    I'm sorry but I don't understand your last reply. Do you mean you want to get name instead of guid?

  • sdnd2000 Profile Picture
    2,510 on at

    Yes, I want get the name as well as the attribute from link entity, like the "resolution date", "Fullname", here is my query

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
        <entity name="account" >
            <attribute name="new_registrationid" />
            <attribute name="new_legalname" />
            <attribute name="primarycontactid" />
            <link-entity name="incident" from="customerid" to="accountid" alias="af" >
                <filter type="and" >
                    <condition attribute="new_resolutiondate" operator="not-null" />
                </filter>
            </link-entity>
            <link-entity name="contact" from="parentcustomerid" to="accountid" alias="ag" >
                <filter type="and" >
                    <condition attribute="new_im_brokerofrecord" operator="eq" value="1" />
                    <condition attribute="fullname" operator="not-null" />
                </filter>
            </link-entity>
        </entity>
    </fetch>
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Try to use something like following:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >

       <entity name="account" >

           <attribute name="new_registrationid" />

           <attribute name="new_legalname" />

           <attribute name="primarycontactid" />

           <link-entity name="incident" from="customerid" to="accountid" alias="af" >

               <filter type="and" >

                   <condition attribute="new_resolutiondate" operator="not-null" />

               </filter>

           </link-entity>

           <link-entity name="contact" from="parentcustomerid" to="accountid" alias="ag" >

               <attribute name="fullname" />

               <filter type="and" >

                   <condition attribute="new_im_brokerofrecord" operator="eq" value="1" />

                   <condition attribute="fullname" operator="not-null" />

               </filter>

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

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