locked
query child entity using parent-child relationship N:1 RRS feed

  • Question

  • Hi Everybody, 

     I have a stupid question regarding query data using Relationsships between two entity types. 

     I have my Parent Entity (Transport)
     I have many Child Entity (TransportLines)
       There are a N:1 Relations ship on the Child Entity to the Parent Entity. (Relationname: Transport_TransportLine)

    It all works fine in CRM, but when I start using the webservice and query the Child Entity, I can't figure out how to get my Child Entities related to each of my Parent Entity. 

    I'm using the xrmServices/2011/organization.svc to retrive data from CRM Online. 

    Are there someone there can give me a example on how to Retrive my child data related to a single Parent Entity.

    Thanks in advance. 
      Lars

    Tuesday, October 8, 2013 3:14 PM

Answers

  • Hi,

    Here is your required fetchxml:-

    Replace Guid {49DD8AA0-7230-E311-940E-0050568D580A} with the Guid of your Parent Entity Transport ID

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="transportline">
        <attribute name="transportlineid" />
        <attribute name="transportLinesName" />
        <attribute name="createdon" />
        <attribute name="transportlinesid" />
        <attribute name="statecode" />
        <order attribute="name" descending="false" />
        <filter type="and">
          <condition attribute="statecode" operator="eq" value="0" />
        </filter>
        <link-entity name="transport" from="transportid" to="transportlinesid" alias="ab">
          <filter type="and">
            <condition attribute="transportid" operator="eq" uiname="test" uitype="transport" value="{49DD8AA0-7230-E311-940E-0050568D580A}" />
          </filter>
        </link-entity>
      </entity>
    </fetch>


    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful" Thanks, Imran Abbasi

    Wednesday, October 9, 2013 12:38 AM

All replies

  • You can do this by using Fetch Xml query.

    click on advance find and in entity field select your child entity after that query the record where your parent Entity record = "XYZ".

    Get Fetch query and use it in your code.

    Refer http://msdn.microsoft.com/en-us/library/gg309565.aspx

    for more information .

    Hope this will help you.


    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.






    Tuesday, October 8, 2013 6:07 PM
  • Hi,

    Here is your required fetchxml:-

    Replace Guid {49DD8AA0-7230-E311-940E-0050568D580A} with the Guid of your Parent Entity Transport ID

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="transportline">
        <attribute name="transportlineid" />
        <attribute name="transportLinesName" />
        <attribute name="createdon" />
        <attribute name="transportlinesid" />
        <attribute name="statecode" />
        <order attribute="name" descending="false" />
        <filter type="and">
          <condition attribute="statecode" operator="eq" value="0" />
        </filter>
        <link-entity name="transport" from="transportid" to="transportlinesid" alias="ab">
          <filter type="and">
            <condition attribute="transportid" operator="eq" uiname="test" uitype="transport" value="{49DD8AA0-7230-E311-940E-0050568D580A}" />
          </filter>
        </link-entity>
      </entity>
    </fetch>


    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful" Thanks, Imran Abbasi

    Wednesday, October 9, 2013 12:38 AM
  • You can always try to create the query using Advanced Find View. Once you get the results, click Download FetchXML to get the fetchxml query for that specific query.

    You can then use this query in your code. It is always easy to get the FetchXML generated from the AdvancedFind Views.

    HTH

    Sam


    Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Proposed as answer by Sam - Inogic Wednesday, October 9, 2013 2:26 AM
    Wednesday, October 9, 2013 2:25 AM