Use Case:
我們已有一個 XML 檔案,需要在 CRM 中按照該XML設定的條件查找相應記錄,但問題是預設情況下,Dynamics 365 (CRM) 不提供直接導入 XML 檔案到進階查找Advanced Find的開箱即用功能。怎麼解決這個問題呢?
今天,我們将使用 Chrome 浏覽器将 XML 檔案轉換為 CRM 進階查找中的過濾器(當然你可以使用其他浏覽器,參考以下方法實施)。 以下是具體步驟。
XML檔案
例如,如果我們已經有一個像下面這樣的 XML 檔案,
```html/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 檔案,然後按照以下步驟操作:
1. 按鍵盤上的 Ctrl + A 選擇整個腳本
2. 在鍵盤上按Ctrl+J,将xml改為單個字元串,然後指派給一個fetchxml變量(變量名也可以使用其他名稱,隻要符合JavaScript的變量命名和聲明規則即可)
```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聯系人實體(或您要查找的實體),然後確定沒有設定任何搜尋條件,即如下圖紅色字型提示區域需要是空白的
如何将XML檔案内容轉換為Dynamics 365進階查找中的篩選條件 - 按鍵盤上的 F12,調出開發者工具
- 如下面截圖中紅色箭頭所示位置,從下拉清單中選擇“contentIFrame0”
如何将XML檔案内容轉換為Dynamics 365進階查找中的篩選條件 - 将JavaScript變量和值複制到Console 中,按 Enter
如何将XML檔案内容轉換為Dynamics 365進階查找中的篩選條件 - 在Console 中輸入以下腳本,然後再次按 Enter 鍵,
$find('advFind').set_fetchXml(fetchxml);