26 Apr, 2023
Posted on 26 Apr, 2023 by Admin, Posted in Dynamics 365 Web Api Dynamics 365
What is Link-Entity
1. To combine data from different records in your query you need to use the
2. Each
2.a. The entity types to link to
2.b. The attribute in the main entity to join from
2.c. The attribute in the another entity to join to
NOTE: If you have a many-to-many (N:N) relationship you can’t join the entities directly, you have to join via the intermediate “intersect” entity.
3. There are two types of link-types: inner and outer.
4. The Link-Entity syntax requires providing of an Alias using which the values of the attributes can be accessed from the result-set.
NOTE: If you do not provide an alias, the platform will auto generate the alias for you.
Example:
Suppose we have a requirement in which we need contact details like fullname, firstname, lastname and the account details like name and phone number that is related to contact.
Solution:
First, we will write a simple FetchXml query for contact in which we will select the attributes like fullname, firstname, lastname.
API Request:
https://dev-onepiece07.api.crm7.dynamics.com/api/data/v9.2/contacts?fetchXml=
Output:
2. As per the requirement that has been mentioned in the example, we will add the link- entity to get the account and its details like name and phone number that are related to contact.
2.a. We will use an inner link-type which will match the data of both the entity, and it will give the result.
API Request:
https://dev-onepiece07.api.crm7.dynamics.com/api/data/v9.2/contacts?fetchXml=
Output:
2.b. We will use an outer link-type which will give all the data of the first entity if there are no matching records.
API Request
https://dev-onepiece07.api.crm7.dynamics.com/api/data/v9.2/contacts?fetchXml=