In continuation of advanced plugin concepts part 1, in this post, we’ll discuss shared variables in ms CRM plugins and how to use them. We’ll also discuss user impersonation in plugins and how we can use it.

Also read: What is Microsoft Dynamics 365?

1. Shared Variables

Microsoft Dynamics 365 Customer Engagement platform and the execution pipeline provides the ability to pass data from one plug-in to another through an IPluginExecutionContext property called SharedVariables. This property is a collection of key/value pairs which developers can use to share data between plug-ins which are registered on both the pre and post events.

Shared Variables are useful for sharing the data during complex Plug-in development by sharing the data between Plugins registered on both the pre and post events.

Any value stored in the Plug-in context of Pre-event will be available in the Post-event of the Plug-in. This way, we can avoid storing the values in a custom attribute. Certain data validation which needs to be done at post-event can be achieved by passing the value from Pre-event of the Plug-in.


Also Read: Impersonation in Dynamics 365 Plugins


Test Case: For a demo, let’s say We want to check if the contact being created is duplicate i.e. contact exists with same first name and last name in Customer Engagement. If it exists, on post-operation, we want to mark the contact status duplicate. [Read More]