Fetch XML is a really handy way of retrieving data from CRM. It is easy to construct complex query and really simple to execute. In this blog article I will explain how you can execute fetch XML query in Dynamic CRM 2011 or CRM online. To start you will first need to download a fetch xml from advanced find and then use the RetrieveMultiple method of the CRM Service to execute the Fetch XML.
First go to Advanced d find and select the entity on which you need to make query


Following is the fetchxml retrieve from Advance Find:
String fetchXml = @"'1.0'?>
'false' mapping='logical' output-format='xml-platform' version='1.0'>
'contact'>
'lastname'/> 'firstname'/>
'contactid'/> 'false' attribute='telephone'/> 'and'>
'vdbwc1_vip' value='1' operator='eq'/>
";
All now that is left is to send a fetch request. This can simply be done by using the following code.
EntityCollection EC = _service.RetrieveMultiple(new FetchExpression(fetchXml));
if (EC != null && EC.Entities != null && EC.Entities.Count >= 1)
{
foreach (Entity E in EC.Entities)
{
Guid entityId = E.Id;
}
}
Above code shows how RetrieveMultiple method is used to retrieve EntityCollection from fetchxml.
Hope this helps. Happy Coding !!