Plugins in Dynamics 365 : Part 6
Hello Guys,
In my previous blogs we have seen how to implement tracing in plugin and Pre-Operation stage. Today we learn another important concept in Dynamics plugin and i.e. Pre Image and Post Image. But before if you are new to our blog then do follow us to know more about Dynamics and Power Platform. Also if you like our blog then please comment and share this blog with your friends.
While using dynamics 365, we are performing many operation like create, update, delete etc. There are many situation where you need to check for the data like what data is created while performing create operation, we want to check before and after value while performing update operation and many more.
Consider a scenario of cash withdrawal machine which contains balance amount. Suppose we are having an account named A which is having 20000₹. Now we are making a transaction that is we are withdrawing 5000₹. Now we want to display balance amount in message also we want to keep previous amount value as record somewhere in database, in this scenario we should be having some mechanism to keep the track of before and after value.
Dynamics 365 Plugins provides the concept of Pre Image and Post Image to achieve this. Now if we consider our cash withdrawal machine example then 20000₹ is Pre Image value and after database transaction 15000₹ is Post Image value.
We can register Pre Image and Post Image after creation or registration of plugin step. As we know that we are having various stage like Pre-Validation,Pre-Operation and Post-Operation, we need to ensure that on which stage we can get Pre-Images and Post-Images for which message. Below are the details:
The following table explains Pre-Image Availability.
Stage | Create | Update | Delete | |||
Pre Operation |
No | Yes | Yes | |||
Post Operation | Yes | Yes | Yes |
The following table explains Post-Image Availability.
Stage | Create | Update | Delete | |||
Pre Operation |
No | No | No | |||
Post Operation | Yes | Yes | No |
Now we will implement Pre-Image and Post-Image in our plugin too.
As you can see in above image, we have Employees along with their Department and Salary. We will update employee data with their new Department and Salary and in Plugin-Trace log we will display before value as well as after value. We will be working on same Project which we have used in Plugin Development series.
Step 1:- Open "DynamicsPlugin" Project in Visual Studio and Add a new class named "UpdateEmployeeSalary". Replace existing code with below one.
Step 2: Build the project and update new dll using plugin registration tool.
Step 3: Now we will be creating a new step on UpdateEmployeeSalary. Right click on it -> Register new step.
Step 4: Now right click on the step which we created and select register new image.
Step 5:- Click on Parameters. Select Department and Salary and click on register image.
Now we will update employee record in CRM and check the functionality. Open any record and change department and Salary and save the record.
Once record is saved, open Plugin Trace log and check for update. you will see below trace logs:
Hope it helps...
👍
ReplyDeleteThanks Ruksar
DeleteWell explained !!!
ReplyDelete