我在MS CRM 2011
- /XRMServices/2011/Organization.svc
中使用新的OrganizationService端點。使用FetchXML條件撰寫RetrieveMultiple查詢
它似乎不支持舊的Fetch
命令。而且,當我發現我仍然可以使用fetchXML
查詢將它傳遞給RetrieveMultiple
方法。
在C#它看起來很簡單:
string expression = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='systemuser'>
<attribute name='businessunitid' />
<attribute name='systemuserid' />
<order attribute='businessunitid' descending='false' />
<filter type='and'>
<condition attribute='systemuserid' operator='eq-userid' />
</filter>
<link-entity name='businessunit' from='businessunitid' to='businessunitid' alias='ah'>
<attribute name='name' />
</link-entity>
</entity>
</fetch>";
FetchExpression fetch = new FetchExpression(expression);
// let's assume GetOrganisationService will return correct instance of IOrganizationService
IOrganizationService service = GetOrganisationService();
EntityCollection result = service.RetrieveMultiple(fetch);
但我需要從JavaScript執行同樣的事情。我不太確定在這種情況下如何編寫正確的查詢。
很顯然,fetchXML
需要以某種方式轉換爲SOAP
,但我刷過遍及Internet和SDK,無法找到如何做到這一點。
我怎麼可以把這種要求:
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='systemuser'>
<attribute name='businessunitid' />
<attribute name='systemuserid' />
<order attribute='businessunitid' descending='false' />
<filter type='and'>
<condition attribute='systemuserid' operator='eq-userid' />
</filter>
<link-entity name='businessunit' from='businessunitid' to='businessunitid' alias='ah'>
<attribute name='name' />
</link-entity>
</entity>
</fetch>
裏面以下SOAP
消息?
<soap:Body>
<RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>
<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:QueryExpression'>
Some magic here
</RetrieveMultiple>
</soap:Body>
嗯,你是對的我還沒有想過這個!我可以使用'REST'端點。不過,我會選擇'JSON'響應而不是'OData'。 – shytikov 2013-03-29 05:53:46
@shytikov OData將以JSON形式返回結果。 OData是使用的「查詢」語言。 – Daryl 2013-03-29 10:32:24
你說得對,對不起,我以爲'OData'是他們送回的醜陋的XML。 – shytikov 2013-03-29 15:11:12