-
Notifications
You must be signed in to change notification settings - Fork 4
Coalescing the Target with an Image
One of the common themes in plugin development is to need to get result view of the target entity as will be after the plugin has been finished. Since by default, the target contains only the information that is included in the update request, this information will need to be coalesced with an image. So basically, combine all of the attributes of the target entity from the database, that I've specified in the pre/post image registration, with the pipeline target itself. The extension class in the DLaB.Xrm namespace adds an extension method to the IPluginExecutionContext interface to simplify this:
using Source.DLaB.Xrm;
...
var currentImage = context.CoalesceTargetWithPreEntity<Contact>();
var firstName = entity.FirstName; // This will be either the first name from the target if it exists, or the first name from the pre-Image
Just be aware the currentImage
variable in the example above is not the actual target, and updating it's attributes will not directly affect the plugin pipeline and be updated in the database (as is the case for the target in Pre Operation Plugins).