Working with Plug-Ins in Dynamics 365

Microsoft Dynamics 365 plug-ins are one of the most commonly used and powerful approaches to extending the application. A plug-in is custom code, written and compiled in .Net, that is “triggered” when a specific event takes place within a specified entity. The objective of custom plug-in code is to enhance or modify the standard features/behavior of Dynamics 365 by injecting custom business logic into the execution of nearly any task a user performs.

Plugin code can be triggered to run when a record is created or updated or perhaps even when a group of records is queried. The Microsoft Dynamics 365 system contains a wide array of these events, commonly referred to as system “Messages”, from which custom code can be triggered. The Messages (which are technically web service operations) are constantly available to run as Dynamics 365 recognizes events within the platform and sends requests to the respective message for the custom logic to interact with your data.

A complete list of event messages can be found within the Microsoft Dynamics 365 SDK.

Tip! Want to learn Dynamics 365 development skills?  Check out Developer Environment and Developer Extending events.

The plug-in code can be written to run before or after, say, a save operation is completed, thus allowing the developer to work with the context of data when writing the new business logic. This allows a programmer to read and analyze the current data and environment to help design the custom business logic.

When plug-ins are triggered through the messaging system, they can be configured to run in various Steps of the execution pipeline within CRM: pre-event and pre-validation, pre-event and pre-operation, and post-event. The step is the “when” of the plug-in execution. These stages are important factors in designing how a plug-in can create the desired outcome for custom business logic.

Another critical concept behind plug-ins is the Image. An image, created when a plug-in is registered within CRM, is a “snapshot” of an entities data context before (pre-image) or after (post-image) the execution of the operation which triggered the plug-in. Again, access to the fields and values of an image provide the developer with valuable context needed when writing the custom business logic.

While plug-ins are a .Net assembly, they are unique in that are “registered” within the Microsoft Dynamics 365 framework. There are a number of important concepts to understand when writing plug-ins

  • Understanding data context that is available to plug-ins when run through different messages and at different stages.
  • Using Steps and Images when registering plug-ins
  • Exception handling within plug-ins (link)
  • Using Impersonation in plug-ins
  • Challenges with debugging a plug-in

Do More with Dynamics 365

Expand your knowledge of Dynamics 365 through PowerObjects’ educational blogs.  Looking to learn in a more formal setting?  Check out our in-person training courses.

Want to learn development skills?  Check out Developer Environment and Developer Extending events.