Contracts, Renewals, and Plugins

I ran into an interesting issue today during a CRM 4.0 upgrade to 2011.

We have a plugin that automatically generates a Contract Detail record when a Contract is created. This is because Contracts need at least one detail record but the customer is not using the actual details.

The issue arose when the Contract was renewed. The Contract Detail creation plugin was fired and it threw an error because it didn’t like something about the Contract Detail record it was creating.

I investigated the Renewal Process and found that we should not be firing the Contract Detail creation plugin during this process because CRM takes care of everything.

Once I made that determination, I had to discover a way to differentiate between Create of a new Contract and Renew of an existing Contract.

Here is my solution:

if (context.ParentContext != null &&
    context.ParentContext.MessageName == MessageName.Renew)

In the case of a Renewal, we will have a sub-step that is actually the Create.  The main, or parent step is actually the Renew.

By checking to see if our Create step has a parent step, AND if that parent step is a Renew message, then I will exit the plugin and not perform the creation of the Contact Detail record.

Leave a Reply 0 comments