› Dynamics 365, Enterprise › Retrieve data using same data type fields from different entities

Retrieve data using same data type fields from different entities

 Subhash Mahato   Leave a comment


We have various methods to query CRM like, “query expression”, “fetch expression” and “LINQ”. If we want to query data of two different entities, then we should have relationship between entities otherwise you will not get data. In case you want to process data of two different entities which are not related to each other then what to do.

We can achieve this using fetch Expression in with the common field data type.


We had a requirement where we wanted to get the data from two different entities which were not related to each other but both of them had common field Email Address. So we can query the CRM using Fetch expression by providing from field and to field which will connect to each other.


To demonstrate this how it works I have tested it with account and contact entities as an example. We are testing it with “email address”. To execute this query XRM tool box is used. You can download it from given link http://www.xrmtoolbox.com/




<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
    <entity name="contact" >
        <attribute name="fullname" />
        <attribute name="emailaddress1" />
        <order attribute="fullname" descending="false" />
        <link-entity name="account" from="emailaddress1" to="emailaddress1" alias="Account" >
            <attribute name="emailaddress1" />
            <attribute name="name" />

As you can see that we have linked contact and account on the basis of emailaddress1. Once you execute the query you will have all the records which are related to each other with same email id

As you can see there are more records matching with same email id on account and contact. So it returns all the records with the matching email id.


You can query CRM data of two different entities using the same data type fields.

Liked it? Share it.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.