【问题标题】:Link an entity that isn't the "Primary" entity链接不是“主要”实体的实体
【发布时间】:2019-01-11 04:28:33
【问题描述】:

有人要求我使用 FetchXML 针对 CRM 中的一些数据创建一份报告。我以前从未使用过这种语言,所以我认为这可能是一个简单的问题。

我有以下代码:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="bie_backbonus" enableprefiltering="1">
    <attribute name="bie_backbonuscontractno" />
    <attribute name="bie_backbonusnoteforletter" />
    <attribute name="bie_offdate" />
    <attribute name="bie_ondate" />
    <attribute name="bie_backbonuscontractversion" />
    <attribute name="bie_backbonuscontractname" />
    <attribute name="bie_backbonuscontactname" />
    <attribute name="bie_legacybackbonuscode" />
    <attribute name="owneridname" />
    <attribute name="createdon" />
<link-entity name="bie_backbonusproductgroup" from="bie_backbonuscontractno" to="bie_backbonusid" alias="pg" link-type="outer">
    <attribute name="bie_tier2percent" />
    <attribute name="bie_tier2value" />
    <attribute name="bie_tier3percent" />
    <attribute name="bie_productsubtype" />
    <attribute name="bie_tier1value" />
    <attribute name="bie_tier3value" />
    <attribute name="bie_producttype" />
    <attribute name="bie_tier1percent" />
 </link-entity>
<link-entity name="bie_producttype" from="bie_name" to="bie_producttype" alias="p" link-type="outer">
    <attribute name="bie_producttypenl" />
</link-entity>
  </entity>
</fetch>

我试图链接上面的三个实体,但 bie_producttype 实体需要链接到 bie_backbonusproductgroup 实体,而不是我认为的 bie_backbonus。是否有一种功能或方法可以链接到“主要”实体以外的其他实体?

我也尝试过使用http://www.sql2fetchxml.com/,但这产生了我的报告无法读取的代码。

我是一名 SQL 开发人员,如果用 SQL 编写代码,代码将是这样的:

SELECT  b.bie_backbonuscontractno
   ,b.bie_backbonusnoteforletter 
   ,b.bie_offdate
   ,b.bie_ondate
   ,b.bie_backbonuscontractversion
   ,b.bie_backbonuscontractname
   ,b.bie_backbonuscontactname
   ,b.bie_legacybackbonuscode
   ,b.owneridname
   ,b.createdon
   ,pg.bie_tier2percent
   ,pg.bie_tier2value
   ,pg.bie_tier3percent
   ,pg.bie_productsubtype
   ,pg.bie_tier1value
   ,pg.bie_tier3value
   ,pg.bie_producttype
   ,pg.bie_tier1percent
   ,p.bie_producttypenl
FROM bie_backbonus b
JOIN bie_backbonusproductgroup pg ON pg.bie_backbonuscontractno =    b.bie_backbonusid
JOIN bie_producttype p ON p.bie_name = pg.bie_producttype

提前感谢您的帮助。

【问题讨论】:

  • 随着您深入了解 FetchXML,请注意您可以从高级查找查询中导出 FetchXML。而且,XrmToolbox 中的FetchXML Builder 工具也很方便。

标签: xml dynamics-crm crm fetchxml


【解决方案1】:

可以在 FetchXML 中嵌套link-entity。查看上面的查询时,您似乎在最外层同时拥有link-entity,这就解释了为什么它与bie_backbonus 而不是您所期望的bie_backbonusproductgroup 连接。

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="bie_backbonus" enableprefiltering="1">
    <attribute name="bie_backbonuscontractno" />
    <attribute name="bie_backbonusnoteforletter" />
    <attribute name="bie_offdate" />
    <attribute name="bie_ondate" />
    <attribute name="bie_backbonuscontractversion" />
    <attribute name="bie_backbonuscontractname" />
    <attribute name="bie_backbonuscontactname" />
    <attribute name="bie_legacybackbonuscode" />
    <attribute name="owneridname" />
    <attribute name="createdon" />
<link-entity name="bie_backbonusproductgroup" from="bie_backbonuscontractno" to="bie_backbonusid" alias="pg" link-type="outer">
    <attribute name="bie_tier2percent" />
    <attribute name="bie_tier2value" />
    <attribute name="bie_tier3percent" />
    <attribute name="bie_productsubtype" />
    <attribute name="bie_tier1value" />
    <attribute name="bie_tier3value" />
    <attribute name="bie_producttype" />
    <attribute name="bie_tier1percent" />
    <!-- ↓ This has been moved inwards -->
    <link-entity name="bie_producttype" from="bie_name" to="bie_producttype" alias="p" link-type="outer">
        <attribute name="bie_producttypenl" />
    </link-entity>
    <!-- ↑ This has been moved inwards -->
 </link-entity>
  </entity>
</fetch>

【讨论】:

    猜你喜欢
    • 2018-08-08
    • 2021-12-15
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-14
    相关资源
    最近更新 更多