Today’s guest blogger is programmer and CRM aficionado Pablo Peralta.
I frequently get this question: When should I write a plug-in in Microsoft Dynamics CRM versus a workflow ? This dilemma is faced whenever custom logic must be executed in a pre and/or post operation.
Peter Hecke of Microsoft created this decision table on MSDN. Here is another pretty cool matrix done by Humberto on how to choose between these options: http://blogs.msdn.com/lezamax/archive/2008/04/02/plug-in-or-workflow.aspx. Additionally, I would like to point out some stuff that could also help when making up your mind.
First of all, remember than both workflows and plug-ins can attach to exactly the same events. Well, plug-ins have available a couple of more events but essentially both work on top of the same event model.Remember also that workflows always run asynchronous and hence, the Asynchronous Processing Service must be running on the server in order to run.
Workflows are more suitable if:
Workflows also allow running child workflows which may make a lot of sense in some scenarios. Nevertheless, be careful if you need the child workflow results in order to make decisions on your main workflow, as child workflows always run asynchronous, which means that it will trigger the child workflow and continue. If you need your primary workflow to wait until child ends, you will need to write a custom activity.
On the other hand, plug-ins are more suitable if:
It is important to note that since Dynamics CRM 4, plug-ins can also be configured to run asynchronous (Mode attribute while registering plug-in). Nevertheless, pre-event asynchronous plug-ins are not supported. In this case, you will have to set it up as synchronous mode.
Another important thing about plug-ins is the Deployment option which says if the plug-in is going to be executed on the server and/or Outlook client. If both executions are set up and client goes offline and online, plug-in calls are triggered after synchronization so be prepared in this case to execute your code twice!
Regarding to security:
However, within plug-ins you can make use of impersonation to work under the credentials of the user who is making the request. For doing so, you just need to pass True to the CreatCrmService method under the context object.If you need to always impersonate with a specific user, you can do that by passing True as above and setting impersonatinguserid attribute while registering the plug-in.It is important to know that plug-in impersonation does not work offline. The logged on user credentials are always used in this case.
Hope it helps to clarify this dilemma and make better decisions.
[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at twitter.com/pabloperalta]
Can anybody tell me the difference between a message and a method in crm