shytikov
shytikov

Reputation: 9558

Composing RetrieveMultiple query with FetchXML condition

I'm using new OrganizationService endpoint in MS CRM 2011/XRMServices/2011/Organization.svc.

It seems to it does not support old Fetch command. And as I find out I still could use fetchXML query by passing it to RetrieveMultiple method.

In C# it does look simple:

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);

But I need to perform the same thing from JavaScript. And I'm not quite sure how it's possible to compose correct query in this case.

Obviously, that fetchXML need to be transformed into SOAP in some kind of way, but I brushed all over Internet and SDK and cannot find the way how to do it.

How could I put this kind of request:

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

Inside following SOAP message?

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

Upvotes: 0

Views: 2345

Answers (2)

TeaDrivenDev
TeaDrivenDev

Reputation: 6629

It's not necessary to build something like that by hand; there are third party libraries like XrmServiceToolkit that can handle all the SOAP stuff and only require you to provide the actual FetchXml. The result will be returned resolved to JavaScript objects already.

Upvotes: 1

Daryl
Daryl

Reputation: 18895

The code required to set call the SOAP Retrieve multiple via SOAP from JavaScript is rather verbose.

Your query is simple enough... Any reason you don't use the OData rest call?

Upvotes: 1

Related Questions