Возвратите родительскую запись вместе со всеми дочерними записями, используя Fetch XML

Я хочу вернуть одну родительскую запись (Цитата) вместе со всеми ее дочерними записями (Сведения о цитате + продукт связанной сущности) для использования в отчете с использованием Fetch XML. В настоящее время я использую структуру родительского отчета-подотчета, но мне нужно получить доступ к данным, которые хранятся в продукте, в родительском отчете.

Я попытался создать XML-запрос Fetch, соответствующий этому сценарию, но мне удалось написать только запрос, который возвращает предварительно отфильтрованный заголовок цитаты, но все сведения о цитате, независимо от того, к какой цитате она принадлежит.

Текущий XML-код извлечения родительского отчета:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="quote" enableprefiltering="1" prefilterparametername="CRM_FilteredQuote">
    <attribute name="name" />
    <attribute name="customerid" />
    <attribute name="statecode" />
    <attribute name="totalamount" />
    <attribute name="discountpercentage" />
    <attribute name="description" />
    <attribute name="new_productsubgroupid" />
    <attribute name="new_masterproductgroupid" />
    <attribute name="quotenumber" />
    <attribute name="ownerid" />
    <attribute name="createdon" />
    <attribute name="quoteid" />
    <attribute name="effectiveto" />
    <attribute name="effectivefrom" />
    <order attribute="quotenumber" descending="true" />
  </entity>
</fetch>

Текущий XML-файл извлечения подотчета:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="quotedetail">
    <attribute name="productid" />
    <attribute name="productdescription" />
    <attribute name="priceperunit" />
    <attribute name="quantity" />
    <attribute name="extendedamount" />
    <attribute name="quotedetailid" />
    <order attribute="productid" descending="false" />
    <filter type="and">
      <condition attribute="quoteid" operator="eq" uitype="quote" value="@QuoteId" />
    </filter>
    <link-entity name="product" alias="product" to="productid" from="productid" link-type="outer" visible="false">
      <attribute name="price" />
    </link-entity>
  </entity>
</fetch>

Моя попытка комбинированного запроса (возвращает одну цитату, но все детали цитаты, независимо от родителя):

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
    <entity name="quote" enableprefiltering="1" prefilterparametername="CRM_FilteredQuote" >
        <attribute name="name" />
        <attribute name="customerid" />
        <attribute name="statecode" />
        <attribute name="totalamount" />
        <attribute name="discountpercentage" />
        <attribute name="description" />
        <attribute name="new_productsubgroupid" />
        <attribute name="new_masterproductgroupid" />
        <attribute name="quotenumber" />
        <attribute name="ownerid" />
        <attribute name="createdon" />
        <attribute name="quoteid" />
        <attribute name="effectiveto" />
        <attribute name="effectivefrom" />
        <order attribute="quotenumber" descending="true" />
        <link-entity name="quotedetail" alias="quoteProduct" to="quoteid" from="quoteid" link-type="outer" enableprefiltering="1" prefilterparametername="CRM_FilteredQuote" >
            <attribute name="productid" />
            <attribute name="productdescription" />
            <attribute name="priceperunit" />
            <attribute name="quantity" />
            <attribute name="extendedamount" />
            <attribute name="quotedetailid" />
            <order attribute="productid" descending="false" />
            <link-entity name="product" alias="product" to="productid" from="productid" link-type="outer" visible="false" >
                <attribute name="price" />
                <attribute name="new_submittleurl" />
            </link-entity>
        </link-entity>
    </entity>
</fetch>

person Josh    schedule 23.07.2019    source источник


Ответы (1)


Попробуйте запрос ниже. Я изменил тип ссылки = «внутренний». Раньше вы использовали внешний, и, следовательно, он возвращал вам все детали цитаты, которые даже не были связаны, и то же самое с деталями продукта.

Дайте мне знать, если это работает для вас.

Вы также можете попробовать этот fetchxml в плагине xrmtoolbox fetchxmlbuilder.

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
    <entity name="quote" enableprefiltering="1" prefilterparametername="CRM_FilteredQuote" >
        <attribute name="name" />
        <attribute name="customerid" />
        <attribute name="statecode" />
        <attribute name="totalamount" />
        <attribute name="discountpercentage" />
        <attribute name="description" />
        <attribute name="new_productsubgroupid" />
        <attribute name="new_masterproductgroupid" />
        <attribute name="quotenumber" />
        <attribute name="ownerid" />
        <attribute name="createdon" />
        <attribute name="quoteid" />
        <attribute name="effectiveto" />
        <attribute name="effectivefrom" />
        <order attribute="quotenumber" descending="true" />
        <link-entity name="quotedetail" alias="quoteProduct" to="quoteid" from="quoteid" intersect="true" enableprefiltering="1" prefilterparametername="CRM_FilteredQuote" >
            <attribute name="productid" />
            <attribute name="productdescription" />
            <attribute name="priceperunit" />
            <attribute name="quantity" />
            <attribute name="extendedamount" />
            <attribute name="quotedetailid" />
            <order attribute="productid" descending="false" />
            <link-entity name="product" alias="product" to="productid" from="productid" intersect="true" visible="false" >
                <attribute name="price" />
                <attribute name="new_submittleurl" />
            </link-entity>
        </link-entity>
    </entity>
</fetch>
person AnkUser    schedule 25.07.2019
comment
Оцените ответ. Я все еще получаю все детали цитаты после изменения типа ссылки на внутренний. - person Josh; 25.07.2019
comment
Я изменил тип ссылки на intersect=true. Не могли бы вы попробовать с обновленным fetchxml - person AnkUser; 26.07.2019
comment
Это дает тот же результат, к сожалению. - person Josh; 26.07.2019