2013-03-27 33 views
0

我在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> 

回答

1

設置c all the SOAP Retrieve multiple via SOAP from JavaScript所需的代碼相當詳細。

你的查詢很簡單...任何你不使用OData休息調用的原因?

+0

嗯,你是對的我還沒有想過這個!我可以使用'REST'端點。不過,我會選擇'JSON'響應而不是'OData'。 – shytikov 2013-03-29 05:53:46

+0

@shytikov OData將以JSON形式返回結果。 OData是使用的「查詢」語言。 – Daryl 2013-03-29 10:32:24

+0

你說得對,對不起,我以爲'OData'是他們送回的醜陋的XML。 – shytikov 2013-03-29 15:11:12

1

沒有必要手工製作這樣的東西;有像XrmServiceToolkit這樣的第三方庫可以處理所有的SOAP內容,只需要提供實際的FetchXml。結果將返回已解析爲JavaScript對象。

+0

我不喜歡使用比現在使用更多第三方庫的想法,但我會檢查它。謝謝! – shytikov 2013-03-29 05:55:22