I recently had an interesting situation with one of our clients who wanted to use a custom entity modeled on the Accounts entity to view their customer data in CRM 2011 and CRM online. The difference was that this entity would have a N:N Relationship with Contacts instead of a 1:N relationship; however, they still wanted to be able to view a rollup of all the Activities and Opportunities from the related Contact and Opportunity records on the custom entity form (see the class diagram below)
So, I did some research and found an article that explains a plugin to handle the RetrieveMultiple message. However, this article was written for CRM 4.0, which is significantly different from our target CRM version CRM 2011 or CRM online. To make it work for the new version, I rewrote the code and utilized the streamline development toolkit provided in CRM SDK 5. The experiment proved successful and I thought it would be helpful to share the solution with other CRM developers out there. Here’s a step by step breakdown of what I did:
Step 1. Create Dynamics CRM 2011 Package project and connect to CRM.
Step 2. In CRM Explorer, right click on the custom entity and select Create plug-in.
Step 3. In the Create Plug-in dialog, select values as below. CRM SDK tool kit will automatically generate a CRM plugin project and the structural code. You just need to implement the PreActivityRetrieveMultiple function as describe in the next step.
Step 4. Implement PreActivityRetrieveMultiple function as below. Some code has been omitted.
protected void ExecutePreActivityRetrieveMultiple(LocalPluginContext localContext)
if (localContext == null)
throw new ArgumentNullException(“localContext”);
//Get the plugin Execution Context and Organization Service
//find all child entities based on the unsecure configuration XML
foreach (XmlNode child in childentities)
string childentityname = child.SelectSingleNode(“./ChildEntityName”).InnerText;
string lookupfield = child.SelectSingleNode(“./Lookup”).InnerText;
string lookupidfield = child.SelectSingleNode(“./Lookupid”).InnerText;
QueryExpression query = new QueryExpression()
EntityCollection ec = service.RetrieveMultiple(query);
foreach (Entity childentity in ec.Entities)
catch (SoapException e)
throw new Exception(e.Detail.InnerText);
//add all child entities into the link criteria for the execution context
if (childids.Count == 0) return;
condition.Operator = ConditionOperator.In;
Step 5. Build and deploy the project. With CRM developer toolkit, you can deploy CRM plugin or custom workflow activity within Visual studio.
Step 6. Test the plugin. Verify the activity associated view in the custom entity. In the standard activities associated view of the custom entity, you should be able to see the activities from child contacts and child opportunities.
As some might have already noted by now, one of the downsides of working with the CRM SDK 5 is that it’s quite different from previous version and some components in the previous version are no longer supported or changed, which can often frustrate the developer. However, I feel that it does streamline the development process of CRM plugins and custom workflow activities and can help to improve the development productivity. Developers can also make other CRM development and customization within Visual Studio.
Interested in receiving more insights like this by email?
[button style=”btn-success btn-lg btn-block” icon=”glyphicon glyphicon-chevron-right” align=”left” iconcolor=”#81d742″ type=”link” target=”true” title=”Get the Newsletter” link=”http://www.catapulterp.com/contact-us/newsletter-sign-up/”]