Here is the scenario:
I remember the days we used to write lengthy code to get all the entities that are not associated with another entity.
Did not understand?? Ok… let me give you an example: I want to get all the cases that are not having tasks associated with them. This is a complex way of getting until CRM 2011. Now things have changed so are we!! Excited?? So let us look into how we can achieve this requirement:
string strFetch = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
<attribute name='title' />
<link-entity name='task' from='regardingobjectid' to='incidentid' alias='ab' link-type='outer'>
<attribute name='regardingobjectid' />
<condition entityname='ab' attribute='regardingobjectid' operator='null' />
In the above fetch xml you can see the link-type being shown as outer and we writing an alias for this entity. Eventually we are writing a condition mapping that alias name.
EntityCollection caseCollection = service.RetrieveMultiple(new
foreach (Entity caseEntity in caseCollection.Entities)
// Create a task activity to follow up with the account customer in 7 days.
Entity followup = new
followup["subject"] = "Send e-mail to the customer.";
"Follow up with the customer. Check if there are any new issues that need resolution.";
followup["scheduledstart"] = DateTime.Now;
followup["scheduledend"] = DateTime.Now.AddDays(7);
followup["category"] = context.PrimaryEntityName;
followup["regardingobjectid"] = new EntityReference("incident", caseEntity.Id);
That is all!!You can relate this with several 1:n relationships that you have in CRM 2013.