Posts Tagged PreEntityImages in Plugins in CRM 2011
PreEntityImages and PostEntityImages In CRM 5.0 / 2011 Plugins
Posted by deepakkumar5035 in CRM, Plugins on February 4, 2011
PreEntityImages :
It is basically used to capture the data when the form loads. That is the data which is present by default when the form loads. The syntax for using the PreEntityImages in CRM 2011 is changed as compared to CRM 4.0. Remember the PreEntityImages cannot be registered for “create” operation.
Syntax Used in CRM 2011 :
Suppose you registered the Plugin and added a Image with name “PreImage ”
Entity preMessageImage;
if (context.PreEntityImages.Contains(“PreImage”) && context.PreEntityImages[“PreImage”] is Entity)
{
preMessageImage = (Entity)context.PreEntityImages[“PreImage”];
accountnumber = (String)preMessageImage.Attributes[“accountnumber”];
}
Here Entity is an Class that is available in the Microsoft.Crm.Sdk.dll
PostEntityImages :
The Post Image contains the attributes value which are finally changed. We can capture the changed data before the database operation takes place. And can do any kind of validation based on the changed data. Remember it can only be registered for update message and cannot be registered on create message.
Syntax Used in CRM 2011 :
Suppose you registered the Plugin and added a Image with name “PostImage ”
Entity postMessageImage;
if (context.PostEntityImages.Contains(“PostImage”) && context.PostEntityImages[“PostImage”] is Entity)
{
postMessageImage = (Entity)context.PostEntityImages[“PostImage”];
accountnumber = (String)postMessageImage.Attributes[“accountnumber”];
}
The PreEntityImages and PostEntityImages are Very useful in Scenarios where we want to compare the data that is changed by the user. Based on the changes the custom operation can be performed.
The below PLugin shows the use of PreEntityImages and PostEntityImages.The plugin creates a contact record when a account record is updated. The plugin uses late binding or Dynamic Entity concept for the creation of the record.