When should I use plug-ins vs. custom workflows?

Roshan Mehta, 27 July 2012

This is a question that plays on a developers mind when working with Microsoft Dynamics CRM. Sometimes the question can be broken down to help evaluate the benefits of one over the other, and other times it just comes down to personal preference. Most developers will always build additional logic using a plug-in, while others will prefer to use workflow processes. Let’s weigh out each of these options to identify the best fit for your Dynamics CRM implementation.

When should I use plugins vs custom workflows*

Is the system on-premise or cloud hosted?

This is an easy question to start with. Currently, Microsoft Dynamics CRM 2011 has restrictions on the types of custom code we can add to a cloud hosted implementation. Plug-ins can be registered in “sandbox” or “isolation” mode which ensures that the code it uses cannot perform certain tasks such as writing to a file, reading/writing from an external database, or interacting with external web services – just so we don’t kill Microsoft’s data centre J. However, custom workflow activities cannot be registered in isolation mode so if you’re running a cloud hosted implementation, you will need to use plug-ins instead of custom workflow activities.

If you’re implementation is hosted on-premise, consider the following questions.

Should the logic be configurable?

Let’s assume we have the following business requirement for a workflow that we will apply to many different CRM systems.

When a Lead gets created, it should be assigned to the sales representative that has the fewest Leads assigned to them. An e-mail message should also be sent to the sales representative to notify that a Lead has been allocated to them.

Perhaps the e-mail notification needs to be configurable. For example, one client might want the message “Hi. The following Lead has been assigned to you” whereas another client might want the message “Hello <User>. A new Lead has been assigned to you for follow up”. We know that the workflow editor in CRM allows us to easily send e-mails and configure the e-mail text so it makes sense to use a custom workflow activity as well as out-of-the-box workflow functionality to achieve this.

What if my plug-in causes performance issues?

Assume that when we update a record in CRM, we need to automatically update hundreds of child records. If we ran this as a plug-in, the user will experience some performance issues on save of the parent record (assuming the plug-in is registered to run synchronously). It may be a better option to execute this as a custom workflow activity to ensure the process runs in the background and will not affect the user experience or we can use an asynchronous plug-in.

How do I solve concurrency issues?

If we want control over the order in which separate pieces of code run, the best option is to use a plug-in. The plug-in registration tool provides an option for us to specify the Execution Order for each plug-in step. For example, we might have many plug-in steps running on update of the Contact entity.

 When should I use plugins vs custom workflows

Workflows run asynchronously so there is no guarantee of controlling when and in which order each custom workflow activity runs.

I hope this gives you some insight into the advantages and disadvantages of plug-ins vs custom workflow activities.

* Image from http://urbanconservativeleague.org/cgi/scratching-head-clipart-i9.gif