When To Utilise The Different Plugin Types (Pre-Validation, Pre-Operation and Post-Operation)

on Monday, 22 July 2013


In Microsoft Dynamics CRM 2011, plugins can be triggered to fire on a variety of messages (update, create, win etc). However you can also specify when exactly the plugin will fire in relation to the given message. Your choice is the following:

  • Pre-validation of the given message (pre-validation of a record deletion for example). 
  • Pre-operation (pre-operation of a record update for example). 
  • Post-operation (post-operation of a record create). 

What trigger point you choose here can be very important, I will attempt to explain here when you should use each type:

Pre-Validation
Firstly, all delete operations that reference the target record will need to be run in this mode. Pre-Validation plugins run before the actual operation is validated within CRM and could allow the user to do such things as custom checks to determine if a record can be deleted at this point in time. 

Pre-Operation
Plugins that fire on this message tend to involve operations which could result in the updating of the target record itself before it is actually saved in the system.

Post-Operation
Note, avoid using this mode if your plugin is going to be updating the current entity. This mode is best utilised when the plugin simply needs to reference the newly created record (but not actually update it) in order to perform further operations on other records in the system.  Problems can arise if you try to update the target entity in a post-op plugin, for example if you have a plugin that runs post-update of an entity and the same plugin updates the target entity, then an infinite loop will occur.

I hope this post was helpful and if you think I've missed anything please leave a comment and let me know!

0 comments:

Post a Comment