Views: 755

PreEntityImages and PostEntityImages contain snapshots of the primary entity's attributes before (pre) and after (post) the core platform operation. Microsoft Dynamics CRM populates the pre-entity and post-entity images based on the security privileges of the impersonated system user. Only entity attributes that are set to a value or are null are available in the pre or post entity images. You can specify to have the platform populate these PreEntityImages and PostEntityImages properties when you register your plug-in. The entity alias value you specify during plug-in registration is used as the key into the image collection in your plug-in code.

Example of PreEntityimage plugin and PostEntityimage plugin:

Let’s take one scenario, update primary contact address fields into account address fields. I added address2 fields into account entity for understand both image operations, save and publish it. Here address1 fields updating are given in post image, address2 fields updating are given in preimage plugin………..

Go to Visual Studio>new project>visual C#>class Library and then give name of the solution >click ok.

image

Next follow the below steps:

Step-1: Add minimum required references:

System. Security

System.Runserialization

System.Servicemodel

Microsoft.Xrm.Sdk

Microsoft.Crm.Sdk.Proxy

Step-2: Extend the class from Microsoft.Xrm.Sdk.Iplugin.

Step-3: Write your code.

image

Code: Entity preimage = (Entity) context.PreEntityImages ["preupdateimage"];

Entity postimage = (Entity) context.PostEntityImages ["postupdateimage"];

These two lines are required for plugin image operations.

Go to solution explorer, Right click on project (preimageplugin1) and then double click on properties.

image

Go to Signing, mark Sign the assembly check box. This is required in order to be able to deploy the plugin.

image

1. Compile the assembly and deploy using Plugin Registration Tool. Go to plugin registration tool and then click on create new connection, give credentials of your CRM then click on login button.

image

2. Follow the below steps.

a) Click on Register button.

b) Select new Register assembly.

c) Specify location of the assembly.

d) Mark Select All check box.

e) Click on Register selected plugins button.

image

3. Next follow the steps

1) Click on Register button.

2) Select Register new step.

3) Give the message name as we have to perform (update), and select primary entity (account)as we have to perform on it, select field name (primarycontactid)as operation performed when the selected field change.

4) Click on Register new step button.

image

4. Next follow the steps.

1) Click on Register button.

2) Select Register new image.

3) Select image type preimage.

4) Give preimage name Entity Alias (which name is mentioned in code that given it).

5) Click on Register image button.

image

5. Create on more image step for postimage

1) Click on Register button.

2) Select Register new image.

3) Select image type postimage.

4) Give preimage name Entity Alias (which name is mentioned in code that given it).

5) Click on Register image button.

image

 

Finally go to CRM for check the output, open account records, select any one record, and change the primary entity name observe the output.

See the below and observe before change the primarycontactid

image

See the below and observe after change the primarycontactid.

image