How to retrieve multiple attributes from multiple entities in CRM 3.0?
For all those who have tried using QueryExpression to retrieve attributes from multiple entities i am sure it is a hard try! But with no fault of your's this seems to be the limitation within CRM 3.0 as QueryExpression just returns one object. So really in CRM 3.0 if you want to return multiple attributes from more than 1 entity you will have to use the CRM 1.2 - FetchXML technique. Here's how the fetchXML looks.
Entities in example include - Property (parent) related to child Meeting Room entity and meeting room is related to Events entity.
You can use Count to restrict the number of records spitted.
Really, if you feel this is all confusing you can use James tool - http://jamesdowney.net/fetchxml.aspx to create an fetchXML for you real quick. It is free!
here's a sample code for FetchXML -
try
{
//set the CRM service instance
CrmService crmService = new CrmService();
crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Retrieve the results.
string result = crmService.Fetch(fetchXML); //fetchXML is the string shown above
return result;
}
catch (System.Web.Services.Protocols.SoapException ex)
{
return ex.Message;
}
CRM gurus say that they MS will try to overcome this limitation in Titan release. Till then this workaround works fine!
1 issue i found hard to meet my requirement was that it spits back flat structure rather than defined hirearchy. The parent record( property in example above) is returned as an XMl element with every child record. I am not sure how do we achieve GroupBy similar to SQL in FetchXML?! Thanks - Dipesh
No comments:
Post a Comment