Hi,
We have a requirement to retrieve an entity (for example, account) and it its associated contacts with its details, then each contact has lookup field that I need to extract the details too (e.g. contactMethod)
For the first call with account, I'm using $expand to contacts, but it seems it is not possible to call another $expand for the lookup of each contact as multiple $expand isn't supported.
Is there an optimal way to retrieve all these information using a single call in Web API?
Currently, I'm looping a call for each contact on the account entity and the performance is not good.
Please advise.
Hi Benjamin,
I'm so happy to hear that you've resolved your problem :)
Please close this thread so that we could help other users with similar issues.
Regards,
Leo
It seems I found a way using FetchXML instead. See example below
<fetch top='50' >
<entity name='mli_policy' >
<all-attributes/>
<filter>
<condition attribute='mli_policyid' operator='eq' value='068bafb7-00da-e911-8144-0050568b0cd5' />
</filter>
<link-entity name='mli_policycontactmethod' from='mli_policyid' to='mli_policyid' link-type='outer' alias='PolicyContactMethod' >
<all-attributes/>
<link-entity name='mli_contactmethod' from='mli_contactmethodid' to='mli_contactmethodid' link-type='outer' alias='ContactMethod' />
</link-entity>
<link-entity name='mli_policyaccountrole' from='mli_policyid' to='mli_policyid' link-type='outer' alias='PolicyAccountRole' >
<all-attributes/>
<link-entity name='contact' from='contactid' to='mli_customerid' link-type='outer' alias='Contact' />
</link-entity>
<link-entity name='mli_policycertificateaccountrole' from='mli_policyid' to='mli_policyid' link-type='outer' alias='PolicyCertificateAccountRole' >
<all-attributes/>
</link-entity>
<link-entity name='mli_policycertificate' from='mli_policyid' to='mli_policyid' link-type='outer' alias='Certificate' >
<all-attributes/>
</link-entity>
<link-entity name='mli_accountfinancialaccount' from='mli_accountfinancialaccountid' to='mli_accountfinancialaccountid' link-type='outer' alias='AccountFinancialAccount' />
</entity>
</fetch>
Hi Partner,
Unfortunately, $expand is only allowed to use one time in each web api, if we use multiple times, we will get error "Query option '$expand' was specified more than once, but it must be specified at most once."
For example I test to get multiple related entities from account and it failed.
https://[OrgURL]/api/data/v9.1/accounts(2901ac3b-d8d8-ea11-a814-000d3a33f24d)?$select=name&$expand=primarycontactid($select=contactid,fullname&$expand=new_customentity($select=new_name))
May I know where you are using this web api? In D365 form or outside D365?
If you are using Web Api in D365 forms, you could use JS code to call web api for multiple relationships query, it is very easy with "Xrm.page.webapi.retrievemultiplereocrds".
If you are using Web Api outside of D365, I suggest you to use fetch Xml instead.
Regards,
Leo
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156