【问题标题】:FetchXML to Get 2nd Relation EntityFetchXML 获取第二个关系实体
【发布时间】:2013-11-27 17:06:26
【问题描述】:

是否可以在视图中显示来自嵌套链接实体的字段?

我有 3 个实体:统计信息、帐户和地址。 Statistics 有一个对 Account 的查找,而 account 有一个对 Address 的查找。 我想要统计视图中所有这些实体的字段。

我已尝试此操作并收到错误:要使用此保存的视图,您必须删除引用已删除或不可搜索项目的条件和列。

    <savedquery>
        <IsCustomizable>1</IsCustomizable>
        <CanBeDeleted>1</CanBeDeleted>
        <isquickfindquery>0</isquickfindquery>
        <isprivate>0</isprivate>
        <isdefault>0</isdefault>
        <returnedtypecode>10008</returnedtypecode>
        <savedqueryid>{df101ac4-2e4d-e311-9377-005056bd0001}</savedqueryid>
        <layoutxml>
          <grid name="resultset" object="10008" jump="sl_name" select="1" preview="1" icon="1">
            <row name="result" id="sl_statisticsid">
              <cell name="sl_amount" width="100" />
              <cell name="sl_date" width="100" />
              <cell name="sl_debtor" width="100" />
              <cell name="sl_divisioncode" width="100" />
              <cell name="sl_source" width="100" />
              <cell name="sl_statstype" width="100" />
              <cell name="relatedAccount.wl_towncity" width="100"/>
              <cell name="relatedAccount.relatedAddress.wl_city" width="100" />
            </row>
          </grid>
        </layoutxml>
        <querytype>0</querytype>
        <fetchxml>
          <fetch version="1.0" output-format="xml-platform" mapping="logical">
            <entity name="sl_statistics">
              <order attribute="sl_amount" descending="false" />
              <attribute name="sl_statstype" />
              <attribute name="sl_source" />
              <attribute name="sl_divisioncode" />
              <attribute name="sl_debtor" />
              <attribute name="sl_date" />
              <attribute name="sl_amount" />
              <link-entity name="account" from="accountid" to="sl_debtor" alias="relatedAccount">
                <attribute name="wl_towncity" />
                <link-entity name="wl_postalcode" from="wl_postalcodeid" to="wl_postaltowncity" alias="relatedAddress">
                  <attribute name="wl_city" />
                </link-entity>
              </link-entity>
              <attribute name="sl_statisticsid" />
            </entity>
          </fetch>
        </fetchxml>
        <LocalizedNames>
          <LocalizedName description="Statistics and Address" languagecode="1033" />
        </LocalizedNames>
      </savedquery>

如果删除此行,则视图有效:

<cell name="relatedAddress.wi_city" width="100" disableSorting="0" />

有谁知道如何从 GridXML 中的嵌套链接实体中引用元素?

我也尝试过这个有问题的行:

<cell name="relatedAccount.relatedAddress.wi_city" width="100" disableSorting="0" />

看起来似乎不可能有一个视图来显示来自嵌套链接实体的字段。

【问题讨论】:

  • 所以这不是 fetch 的问题,而是导入解决方案的问题?
  • 解决方案不会导入,因为保存的查询不好;如果我删除嵌套的链接实体,那么解决方案就会导入。

标签: dynamics-crm-2011 fetchxml


【解决方案1】:

据我所知,这是不可能的,但请有人证明我错了。

GridXML 的一个限制似乎是只能包含来自第一个链接实体的属性,而不是任何嵌套的链接实体。

【讨论】:

    【解决方案2】:

    可以通过嵌套访问相关实体的数据

    <link-entity>
    

    标签,这是您在发布的代码中所做的。您发布的 fetchxml 有哪些问题?您是收到错误还是没有得到正确的结果。

    【讨论】:

    • 我更新了重新导入解决方案时出现的错误。
    • 您也可以发布您的 GridXML。如果视图位于 sb_statistics 上,则 fetchxml 中的顶级实体应该是 sb_statistics,因此我们可以消除您发布的第二个示例。该错误可能是由于您的 GridXML 和 FetchXML 之间的不一致
    【解决方案3】:

    这是我的 FetchXml 的一个示例:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" aggregate="true">
      <entity name="new_coursesection">
        <attribute name="new_coursesectionid" groupby="true" alias="id" />
        <filter type="and">
          <condition attribute="new_coursesectionid" operator="eq" value="{0}" />
        </filter>
        <link-entity name="new_contactcoursesection" from="new_coursesectionid" to="new_coursesectionid" alias="new_contactcoursesection1" link-type="outer">
          <attribute name="new_contactcoursesectionid" aggregate="countcolumn" alias="contactcoursesectioncount" />
        </link-entity>
      </entity>
    </fetch>
    

    我正在做一个汇总,但你不应该这样做。我会尝试为您的链接实体和属性提供别名。

    【讨论】:

    • 如果视图来自统计实体,那么 fetch 必须具有 或者它可以以 开头以从“由外而内”。
    • @Bvrce 我猜是这样,但我不知道。
    猜你喜欢
    • 1970-01-01
    • 2020-10-19
    • 1970-01-01
    • 2015-04-08
    • 2019-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多