Retrieving Pre and Post data in MSCRM Plug-ins (Create, Update and Delete)
Tuesday, January 12th, 2010
When you look at the sample of plug-in in the SDK they all use the InputParameters property bag. The InputParameters property bag contains all the information specified in the Request class whose message caused the plug-in to execute. As the request class does not include the pre and post data of the entity, the InputParameters property does not contain the pre and post data. The InputParameters property does contain a “Target” property which is a Dynamic Entity of the data that was changed in your entity. Note: The target Dynamic Entity only has the properties (fields) that where changed.
To get the pre and post date of an Entity in a plug-in you need to use the context.PreEntityImages and context.PostEntityImages property bags. You will also need to add an image. In the image you give it an alias and indicate if it is pre and/or post and also define what attributes (fields) you need.

If you don’t know or the fields could change leave the attributes as all fields. If you only need a few fields everything should run faster if you just indicate the fields you need. Now to get a pre DynamicEntity in your plug-in you use context.PreEntityImages.Properties["image alias"]. Note in the following code I first check that the PreEntityImages.Properties contains the “image alias” and the the property is a DynamicEntity.
DynamicEntity preSaveEntity;
DynamicEntity postSaveEntity;
if (context.PreEntityImages.Properties.Contains(“icrmAddress”) && context.PreEntityImages.Properties["icrmAddress"] is
DynamicEntity)
{
preSaveEntity = (DynamicEntity)context.PreEntityImages.Properties["icrmAddress"];
}
if (context.PostEntityImages.Properties.Contains(“icrmAddress”) && context.PostEntityImages.Properties["icrmAddress"] is
DynamicEntity)
{
postSaveEntity = (DynamicEntity)context.PostEntityImages.Properties["icrmAddress"];
}
You are not always going to have a pre and post data it will depend on the Message(Create, Update, Delete, etc) and the Eventing Pipeline Stage of Execution (Pre Stage or Post Stage).
Need a custom MSCRM Plug-in created contact iCRM at http://www.icrm.ca or through
.
I used CRM Plugin Registration Tool 2.2