title: Return parent record along with all child records using Fetch XML
body: <p>I want to return one parent record (Quote) along with all of its child records (Quote Details + linked entity Product) for use in a report using Fetch XML. I am using the Parent Report-Sub Report structure currently, but I need to access data that is stored on the Product in the Parent report.</p>
  
  <p>I have attempted to create a Fetch XML query that fits this scenario, but I have only been able to write a query that returns the pre-filtered Quote header but all Quote Details regardless of which quote it belongs to.</p>
  
  <p>The current Parent Report Fetch XML: </p>
  
  <pre><code>&lt;fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"&gt;
    &lt;entity name="quote" enableprefiltering="1" prefilterparametername="CRM_FilteredQuote"&gt;
      &lt;attribute name="name" /&gt;
      &lt;attribute name="customerid" /&gt;
      &lt;attribute name="statecode" /&gt;
      &lt;attribute name="totalamount" /&gt;
      &lt;attribute name="discountpercentage" /&gt;
      &lt;attribute name="description" /&gt;
      &lt;attribute name="new_productsubgroupid" /&gt;
      &lt;attribute name="new_masterproductgroupid" /&gt;
      &lt;attribute name="quotenumber" /&gt;
      &lt;attribute name="ownerid" /&gt;
      &lt;attribute name="createdon" /&gt;
      &lt;attribute name="quoteid" /&gt;
      &lt;attribute name="effectiveto" /&gt;
      &lt;attribute name="effectivefrom" /&gt;
      &lt;order attribute="quotenumber" descending="true" /&gt;
    &lt;/entity&gt;
  &lt;/fetch&gt;
  </code></pre>
  
  <p>The current Sub Report Fetch XML:</p>
  
  <pre><code>&lt;fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"&gt;
    &lt;entity name="quotedetail"&gt;
      &lt;attribute name="productid" /&gt;
      &lt;attribute name="productdescription" /&gt;
      &lt;attribute name="priceperunit" /&gt;
      &lt;attribute name="quantity" /&gt;
      &lt;attribute name="extendedamount" /&gt;
      &lt;attribute name="quotedetailid" /&gt;
      &lt;order attribute="productid" descending="false" /&gt;
      &lt;filter type="and"&gt;
        &lt;condition attribute="quoteid" operator="eq" uitype="quote" value="@QuoteId" /&gt;
      &lt;/filter&gt;
      &lt;link-entity name="product" alias="product" to="productid" from="productid" link-type="outer" visible="false"&gt;
        &lt;attribute name="price" /&gt;
      &lt;/link-entity&gt;
    &lt;/entity&gt;
  &lt;/fetch&gt;
  </code></pre>
  
  <p>My attempt at a combined query (returns a single Quote, but all Quote Details, regardless of parent): </p>
  
  <pre><code>&lt;fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" &gt;
      &lt;entity name="quote" enableprefiltering="1" prefilterparametername="CRM_FilteredQuote" &gt;
          &lt;attribute name="name" /&gt;
          &lt;attribute name="customerid" /&gt;
          &lt;attribute name="statecode" /&gt;
          &lt;attribute name="totalamount" /&gt;
          &lt;attribute name="discountpercentage" /&gt;
          &lt;attribute name="description" /&gt;
          &lt;attribute name="new_productsubgroupid" /&gt;
          &lt;attribute name="new_masterproductgroupid" /&gt;
          &lt;attribute name="quotenumber" /&gt;
          &lt;attribute name="ownerid" /&gt;
          &lt;attribute name="createdon" /&gt;
          &lt;attribute name="quoteid" /&gt;
          &lt;attribute name="effectiveto" /&gt;
          &lt;attribute name="effectivefrom" /&gt;
          &lt;order attribute="quotenumber" descending="true" /&gt;
          &lt;link-entity name="quotedetail" alias="quoteProduct" to="quoteid" from="quoteid" link-type="outer" enableprefiltering="1" prefilterparametername="CRM_FilteredQuote" &gt;
              &lt;attribute name="productid" /&gt;
              &lt;attribute name="productdescription" /&gt;
              &lt;attribute name="priceperunit" /&gt;
              &lt;attribute name="quantity" /&gt;
              &lt;attribute name="extendedamount" /&gt;
              &lt;attribute name="quotedetailid" /&gt;
              &lt;order attribute="productid" descending="false" /&gt;
              &lt;link-entity name="product" alias="product" to="productid" from="productid" link-type="outer" visible="false" &gt;
                  &lt;attribute name="price" /&gt;
                  &lt;attribute name="new_submittleurl" /&gt;
              &lt;/link-entity&gt;
          &lt;/link-entity&gt;
      &lt;/entity&gt;
  &lt;/fetch&gt;
  </code></pre>