首页 > 解决方案 > 包含空值的 FetchXML 链接实体

问题描述

我正在尝试使用 FetchXML 查询 CRM。这是对帐户实体的查询,这返回了 10 条记录,这里new_primaryactivityname字段有NULL几条记录。

<fetch mapping="logical" version="1.0">
  <entity name="account">
    <attribute name="accountid" />
    <attribute name="name" />
    <attribute name="new_primaryactivity" />
  </entity>
</fetch>

现在我想将它与另一个实体链接以获得一个新字段,我想LEFT OUTER JOIN在 sql 中做类似的事情,以在链接时保留NULL值,所以我将链接类型提供为外部,并针对少数条件应用了过滤器。

<fetch mapping="logical" version="1.0">
  <entity name="account">
    <attribute name="accountid" />
    <attribute name="name" />
    <attribute name="new_primaryactivity" />
    <link-entity name="stringmap" from="attributevalue" to="new_primaryactivity" alias="new_primaryactivity_lookup_name" link-type="outer">
       <attribute name="value" />
    </link-entity>
    <filter type="and">
        <condition entityname="new_primaryactivity_lookup_name" attribute="attributename" operator="eq" value="new_primaryactivity" />
        <condition entityname="new_primaryactivity_lookup_name" attribute="objecttypecode" operator="eq" value="999" />            
    </filter>
  </entity>
</fetch>

结果(少于 10 条记录)忽略了带有new_primaryactivityname的记录NULL,我在 FetchXML 查询中缺少什么?

除了使用 FetchXML 之外,我对系统没有太多访问权限,我提出了一些使用工具来帮助构建 FetchXML 查询的建议,但由于限制我不能这样做。

标签: dynamics-crmfetchxml

解决方案


我认为这是您的过滤器块的位置。

按照现在的编写方式,您将链接accountstringmap与外连接一起,然后将过滤器应用于结果。

我认为你需要outer-join像这样在里面做过滤器:

<fetch mapping="logical" version="1.0">
  <entity name="account">
    <attribute name="accountid" />
    <attribute name="name" />
    <attribute name="new_primaryactivity" />
    <link-entity name="stringmap" from="attributevalue" to="new_primaryactivity" alias="new_primaryactivity_lookup_name" link-type="outer">
       <attribute name="value" />
       <filter type="and">
          <condition attribute="attributename" operator="eq" value="new_primaryactivity" />
          <condition attribute="objecttypecode" operator="eq" value="999" />            
       </filter>
    </link-entity>
  </entity>
</fetch>

或者,您可以尝试以不同的方式编写过滤器并明确允许空值

<fetch mapping="logical" version="1.0">
  <entity name="account">
    <attribute name="accountid" />
    <attribute name="name" />
    <attribute name="new_primaryactivity" />
    <link-entity name="stringmap" from="attributevalue" to="new_primaryactivity" alias="new_primaryactivity_lookup_name" link-type="outer">
       <attribute name="value" />
    </link-entity>
    <filter type="or">
      <condition entityname="new_primaryactivity_lookup_name" attribute="attributename" operator="eq" value="" />
      <filter type="and">
        <condition entityname="new_primaryactivity_lookup_name" attribute="attributename" operator="eq" value="new_primaryactivity" />
        <condition entityname="new_primaryactivity_lookup_name" attribute="objecttypecode" operator="eq" value="999" />            
      </filter>
    </filter>
  </entity>
</fetch>

我没有测试过这些,但希望其中一个对你有用


推荐阅读