top of page

Convert queries from QueryExpression to FetchXML




Often when developing high scale projects, and when performance is very crucial and critical if needed any aggregation function on a Plugin, Custom Workflow Activity or even a custom Application when retrieving data from crm, we should use Fetch XML. When i have to do that, usually i have two options use an advanced find to get the xml (Button that says Download Fetch XML), or we can use a method from the SDK to do the same, please see the below example:

Where queryExpression is a QueryExpression type.

var conversionRequest = new QueryExpressionToFetchXmlRequest { Query = queryExpression }; var conversionResponse = (QueryExpressionToFetchXmlResponse)_serviceProxy.Execute(conversionRequest); // Use the converted query to make a retrieve multiple request to Microsoft Dynamics CRM. String fetchXml = conversionResponse.FetchXml; var fetchQuery = new FetchExpression(fetchXml); EntityCollection result = _serviceProxy.RetrieveMultiple(fetchQuery);

And here it is, hope it helps.

31 views0 comments

Recent Posts

See All
bottom of page