Use Case:
我们已有一个 XML 文件,需要在 CRM 中按照该XML设定的条件查找相应记录,但问题是默认情况下,Dynamics 365 (CRM) 不提供直接导入 XML 文件到高级查找Advanced Find的开箱即用功能。怎么解决这个问题呢?
今天,我们将使用 Chrome 浏览器将 XML 文件转换为 CRM 高级查找中的过滤器(当然你可以使用其他浏览器,参考以下方法实施)。 以下是具体步骤。
XML文件
例如,如果我们已经有一个像下面这样的 XML 文件,
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="contact">
<attribute name="fullname" />
<attribute name="telephone1" />
<attribute name="contactid" />
<order attribute="fullname" descending="false" />
<filter type="and">
<condition attribute="firstname" operator="eq" value="alex" />
<condition attribute="mobilephone" operator="eq" value="619-555-0129" />
</filter>
</entity>
</fetch>
将 xml 文件转换为 JavaScript 字符串
使用 notepad++ 或您可以获得的任何其他文本和源代码编辑器打开 xml 文件,然后按照以下步骤操作:
- 按键盘上的 Ctrl + A 选择整个脚本
- 在键盘上按Ctrl+J,将xml改为单个字符串,然后赋值给一个fetchxml变量(变量名也可以使用其他名称,只要符合JavaScript的变量命名和声明规则即可)
fetchxml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"> <entity name="contact"> <attribute name="fullname" /> <attribute name="telephone1" /> <attribute name="contactid" /> <order attribute="fullname" descending="false" /> <filter type="and"> <condition attribute="firstname" operator="eq" value="alex" /> <condition attribute="mobilephone" operator="eq" value="619-555-0129" /> </filter> </entity> </fetch>';
在高级查找中将 JavaScript 转换为过滤器
-
登入Dynamics 365,然后打开Advanced Find高级查找,找到Contact联系人实体(或您要查找的实体),然后确保没有设定任何搜索条件,即如下图红色字体提示区域需要是空白的

-
按键盘上的 F12,调出开发者工具
-
如下面截图中红色箭头所示位置,从下拉列表中选择“contentIFrame0”

-
将JavaScript变量和值复制到Console 中,按 Enter

-
在Console 中输入以下脚本,然后再次按 Enter 键,
$find('advFind').set_fetchXml(fetchxml);

最终,你将在高级查找中看到相应的过滤器设定

另外,你也可以在以下网址找到我的英文版本文章 https://dtitech.co/tip-how-to-convert-an-xml-file-to-filters-in-advanced-find-in-dynamics-365-crm/
















