For ex: I have 3 entities Customer, Application, Cases. Customer form needs to get Start date, end date from Case form and calculate the diff between dates.
Case from has Application ID which is also present in Customer form. How can i get the customer entity from Application ID found in Case and update dates from case to customer? I am developing a plugin and should there be a relationship or lookup fields? The similar functionality can be achieved with 'Advanced Find' when a entitiy and its attribute values are given Advance Find fetches all the results.
Any help is greated appreciated!!
Best How To :
Like Henk van Boeijen said you could do the following:
private void DoFetchXmlToQueryExpressionConversion()
// Create a Fetch query that we will convert into a query expression.
var fetchXml =
@"<fetch mapping='logical' version='1.0'>
<attribute name='name' />
<condition attribute='estimatedclosedate' operator='next-x-fiscal-years' value='3' />
<link-entity name='account' from='accountid' to='customerid'>
<link-entity name='contact' from='parentcustomerid' to='accountid'>
<attribute name='fullname' />
<condition attribute='address1_city' operator='eq' value='Bellevue' />
<condition attribute='address1_stateorprovince' operator='eq' value='WA' />
// Run the query with the FetchXML.
var fetchExpression = new FetchExpression(fetchXml);
EntityCollection fetchResult =
Console.WriteLine("\nOutput for query as FetchXML:");
// Convert the FetchXML into a query expression.
var conversionRequest = new FetchXmlToQueryExpressionRequest
FetchXml = fetchXml
var conversionResponse =
// Use the newly converted query expression to make a retrieve multiple
// request to Microsoft Dynamics CRM.
QueryExpression queryExpression = conversionResponse.Query;
EntityCollection result = _serviceProxy.RetrieveMultiple(queryExpression);
// Display the results.
Console.WriteLine("\nOutput for query after conversion to QueryExpression:");
That came from here
You could also do a Linq Query in a similar fashion.
Finding the Relationship name: Go to System > Customize > Case > view the Relationships (1:N / N:1 / N:N) find the right relationship with your Application click on it, view > Get the 'Name' this is the Schema Name. If your queries have this schema name as its link(join) you should get the right results.