【问题标题】:Return parent record along with all child records using Fetch XML使用 Fetch XML 返回父记录和所有子记录
【发布时间】:2019-07-23 20:41:12
【问题描述】:

我想返回一个父记录(报价单)及其所有子记录(报价单详细信息 + 链接实体产品),以便在使用 Fetch XML 的报告中使用。我目前使用的是父报表-子报表结构,但我需要访问存储在父报表中的产品上的数据。

我试图创建一个适合这种情况的 Fetch XML 查询,但我只能编写一个查询,该查询返回预过滤的 Quote 标头但所有 Quote 详细信息,无论它属于哪个报价。

当前父报告获取 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>

【问题讨论】:

    标签: reporting-services dynamics-365 fetchxml


    【解决方案1】:

    试试下面的查询, 我改变的是 link-type="inner" 之前您使用了外层,因此它返回了所有的报价细节,这些细节甚至没有链接,并且与产品细节相同。

    让我知道这是否适合你。

    您也可以在 xrmtoolbox 插件 fetchxmlbuilder 中尝试这个 fetchxml。

    <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>
    

    【讨论】:

    • 感谢您的回复。将链接类型更改为内部后,我仍然可以获取所有报价详情。
    • 我将链接类型更改为 intersect=true。您可以尝试更新 fetchxml
    • 不幸的是,这给出了相同的结果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-17
    • 1970-01-01
    • 2017-10-05
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多