我在MS CRM 2011
—中使用新的 OrganizationService 端点/XRMServices/2011/Organization.svc
。
它似乎不支持旧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
某种方式转换,但我刷遍了互联网和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>