简体   繁体   中英

Dynamics 365 OData getting 1:N linked entities

I have entities of type account which when I look at it in Dyn365 it has a section containing a list view of related entities. How do i get these related entities from the OData API?

I can query api/data/v9.1/account but the related entities do not appear anywhere in the resulting json.

If I do the same for the related entities the account do not appear anywhere. How do I get the link between these two types of entities? using the OData API.

I've tried things like /accounts?$expand=contact($select=foo) but it just says contact property do not exist on the account entity, which is correct. But contact is not a property its an entity type.

Probably, this is what you are looking for. The relationship for 1:N between account and contact is contact_customer_accounts

All accounts with its related contacts:

https://crmdev.crm.dynamics.com/api/data/v9.1/accounts?$select=name&$expand=contact_customer_accounts($select=fullname)

Particular account with related contacts:

https://crmdev.crm.dynamics.com/api/data/v9.1/accounts(73C84814-729B-EA11-A811-000D3A370DB6)?$select=name&$expand=contact_customer_accounts($select=fullname)

Solution is to use the following url to get the names of all relationships.

https://<company>.crm.dynamics.com/api/data/v9.1/RelationshipDefinitions?$select=SchemaName

Result is an array of the following rows for each relationship.

{"@odata.type":"#Microsoft.Dynamics.CRM.OneToManyRelationshipMetadata","SchemaName":"aaa_bbb","MetadataId":"<guid>"},

Then use those names, specifically the SchemaName property in the $expand query parameter.

https://crmdev.crm.dynamics.com/api/data/v9.1/accounts?
$select=<whatever>&
$expand=aaa_bbb($select=<properties from linked entity>)

To figure out what relationship actually do what you need, you need to read in more then just the SchemaName if you can't guess what is what, or look it up in Dynamics through the GUI if you know how and have access. I don't.

The RelationshipDefinition contains other properties like ReferencedEntity ReferencingEntity that can be used to determine if you got the right relationship.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM