Plug-ins are a huge improvement over the callouts available in MS CRM 3.0. They are much more flexible, much easier to deploy, and have a many more triggers allowing a lot more access to the inner operation of your CRM system.
The following comparison shows some of the key differences:
Callout | Plug-in |
Deployment | |
Requires Workflow service to be restarted to re-read the callout.config.xml which defines which assemblies and classes to call for each triggered event. |
|
Requires assemblies be copied to each CRM server in your web server farm. Because those assemblies can be busy this can require:
|
|
|
|
Flexibility | |
Requires a different interface for each Message. A PreCreate has a different interface from a PostCreate, or a PreUpdate, or a PostUpdate. | Has the same interface for all messages. |
Supports many more messages | |
Has parent and child pipeline feature | |
Has the ability to watch for endless loops. | |
Coding | |
Requires parsing Xml images to see the contents of the entity generating the message: preImageEntityXml, postImageEntityXml | Returns a Dynamic Entity or Moniker instead. var entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target]; var myMoniker = (Moniker)context.InputParameters.Properties[ParameterName.Target]; |
Allows validity checking and stopping a change to the database in a preCallout errorMessage = "Validation Failed."; return PreCalloutReturnValue.Abort; | Allows validity checking and stopping an operation in a Pre message. throw new InvalidPluginExecutionException( |
Allows modifying data before it is written to the database in a preCallout. Parse and Modify the entityXML | Allows modifying data before it is written to the database in a Pre message. Modify the Dynamic entity. String nameProperty = entity.Properties["name"] as String; |
Resources
VS Plug-in template This template will create a basic Plug-in Project and is a good starting point.
- The example it creates is for a Dynamic Entity Target. This is useful for Create and Update messages, but many other messages will return a Moniker which gives you the id of the calling entity.
- The template includes code to call a customized crmservice which can be useful, although it is faster and a better practice to call your service from the context as shown below if you are comfortable with Dynamic Entities:
ICrmService service = context.CreateCrmService(true);
Plugin Deployment Tool This tool will allow you a simple way to deploy your plug-ins. and has an easy to use UI.
With plug-ins it is important to learn about Dynamic Entities.
If you purchase David Yak's CRM as a Rapid Development Platform, it comes with a number of helper classes for Dynamic Entities, and plug-ins as well as other useful tools that are interesting. His chapters on plug-ins and dynamic entities are useful, and the code he provides is worth downloading and referring to. He also has chapters specific to using his plug-in framework for debugging and other tasks which are not CRM development generic.
I recently ordered a copy of Programming Microsoft Dynamics CRM 4.0, and I'll try to remember to update this post after I have looked over its coverage of Plug-ins and dynamic entities.
No comments:
Post a Comment