dynamics-crm - 包含空值的 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 查询的建议,但由于限制我不能这样做。
解决方案
我认为这是您的过滤器块的位置。
按照现在的编写方式,您将链接account
并stringmap
与外连接一起,然后将过滤器应用于结果。
我认为你需要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>
我没有测试过这些,但希望其中一个对你有用
推荐阅读
- express - 使用 graphql-yoga 使用 Next.js 清理 URL
- vue.js - 无法使用 vuex 实现 Search()
- tensorflow - 拟合生成器函数中的数据增强错误
- ansible - 带有字符串列表的 Ansible 构建列表字典
- python - 合并两个数据框时出错
- haskell - 未能 putStrLn 刚刚分配的东西
- python - 我正在尝试使用 pandas TimeGrouper 创建一些日期的频率表,但是它返回错误
- arrays - 比较后如何显示数组元素的位置?
- android - 在代码部分需要不同 API 的情况下,支持具有不同最低 API 级别的构建的最有效方法是什么
- regex - 如何从 `|` 到 `|` 进行选择?