關注本人微信和易信公衆號: 微軟動態CRM專家羅勇 ,回覆243或者20170111可方便獲取本文,同時能夠在第一間獲得我發佈的最新的博文信息,follow me!個人網站是 www.luoyong.me 。api
Dynamics CRM SDK中的Query Data using the Web API介紹了Web API的使用,提到了標準的過濾操做,包括括號的使用(叫作分組操做符),舉得例子是 (contains(name,'sample') or contains(name,'test')) and revenue gt 5000 。在實際的使用中,這個返回的結果卻不是我想要的,個人理解是括號裏面的先運算,而後在運算括號外面的。爲了更好的說明我以具體的例子來講。微信
下面這個查詢:app
https://demo.luoyong.me/api/data/v8.1/accounts?$select=name,revenue&$count=true&$filter= contains(name,'a') and revenue gt 100ide
返回了4條記錄以下:fetch
而後我在用另一個查詢:網站
https://demo.luoyong.me/api/data/v8.1/accounts?$select=name,revenue&$count=true&$filter= contains(name,'阿') and revenue gt 100orm
返回結果有1條記錄,以下:xml
若是我用or加上括號把條件組合起來呢?查詢以下:blog
https://demo.luoyong.me/api/data/v8.1/accounts?$select=name,revenue&$count=true&$filter= (contains(name,'a') or contains(name,'阿')) and revenue gt 100v8
個人想法是會返回5條記錄,實際結果讓我大跌眼鏡,返回11條記錄,不少不符合條件的記錄也出來了,以下:
這是個產品BUG?仍是我理解錯誤了?我怎麼樣才能GET爭取的使用or 和 and的正確姿式呢?
固然我知道使用fetchXml查詢的結果是正確的,構造以下:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"> <entity name="account"> <attribute name="name" /> <attribute name="primarycontactid" /> <attribute name="telephone1" /> <attribute name="accountid" /> <order attribute="name" descending="false" /> <filter type="and"> <filter type="or"> <condition attribute="name" operator="like" value="%a%" /> <condition attribute="name" operator="like" value="%阿%" /> </filter> <condition attribute="revenue" operator="gt" value="100" /> </filter> </entity></fetch>
,使用Web API執行fetchXml執行的結果也是正確的。問題是我想用普通的Web API,誰知道答案?
羅勇2017年5月10日補充,將CRM從Dynamics CRM V8.1升級到Dynamics 365之後就沒問題了,這個BUG修復了,雖然我在其對應的知識庫文章中沒有看到提到修復這個問題的內容。