locked
Dynamics CRM Online: How to retrieve related entity data from the primary entity. RRS feed

  • Question

  • Dynamics CRM Online: How to retrieve related entity data from the primary entity.

    Example: Account is a Primary Entity and Area is the related entity. These 2 entities have N:N relationship.

    WE need to retrieve all Active Account records and also it should retrieve multiple Area records associated with Account.

    Additionally, I have tried this https://www.inogic.com/blog/2011/09/retrieve-related-entity-records-along-wih-the-primary-entity-using-retrieve-method/ what exactly I am looking for but it will retrieve only one record with service call/request as it have limitation of not using RetrieveMultiple(). Is there any other way that we can make it successful with one service call? 

    Any help on this would be great!


    Madhu M.


    • Edited by Madhu_M Saturday, June 17, 2017 7:21 AM Updated More information
    Saturday, June 17, 2017 1:38 AM

All replies

  • Hello,

    I would suggest to build FetchXml for that purpose (using Advanced Find for example) and use it in WebApi call - https://msdn.microsoft.com/en-us/library/mt607533.aspx#bkmk_useFetchXML


    Dynamics CRM/Business Solutions MVP
    Read My blog

    Saturday, June 17, 2017 2:39 AM
    Moderator
  • Thanks for your Response.

    We cannot build FetchXMLQuery for the current scenario because these 2 entities have N:N relationship which means they do not have lookup fields or any other attributes to build a Query. Hence we need to query only based on Relationship between these may be using RelationshipQueryCollection. But limitation of using this is we can’t get Retrieve Multiple Primary and related entity records.


    Madhu M.

    Saturday, June 17, 2017 7:15 AM
  • Madhu,

    Just FYI. It is possible to build query using FetchXml because when N-N relationship is created intersection entoty is created that contains lookups on both entities. Try to build your request using Advanced Find of FetchXml Builder plugin from XrmToolbox and you will see it's possible. Good luck.


    Dynamics CRM/Business Solutions MVP
    Read My blog


    Saturday, June 17, 2017 2:43 PM
    Moderator
  • I am not able to find any Lookup field related to this entity Area. Also I have cross verified that N:N relationship(only 1:N and N:1 have lookups) doesn't have lookups to query the data. All the related records of any entity will be visible in the subgrid of the related entity.


    Madhu M.

    Sunday, June 18, 2017 11:12 AM
  • If you can't find it it doesn't mean that it's not there. Try to use XrmToolbox with FetchXml builder plugin. It should help you to find "lost" relationship entity.

    Dynamics CRM/Business Solutions MVP
    Read My blog

    Sunday, June 18, 2017 1:01 PM
    Moderator
  • I am looking for common entity between these 2(Primary and secondary) entities that was created as part of this relationship. If I find the schema name of the entity then I think we can build the QueryExpression or FETCHXML for the related entity data.


    Madhu M.

    Sunday, June 18, 2017 6:28 PM
  • It's simple to find that name - just open N-N relationship between entities. It will be there as it shown on following screenshot:


    Dynamics CRM/Business Solutions MVP
    Read My blog

    Monday, June 19, 2017 3:06 AM
    Moderator