Welcome to Dynamics in Motion

Step-by-Step Guide: Writing a Simple Dynamics 365 Plugin to Enhance CRM Capabilities

Step-by-Step Guide: Writing a Simple Dynamics 365 Plugin to Enhance CRM Capabilities

Writing a Simple Dynamics 365 Plugin

Dynamics 365 is a powerful tool for businesses to manage their customer relationship management (CRM) and enterprise resource planning (ERP) software. It offers a wide range of functionalities that can be customized according to the needs of the organization. One way of customizing Dynamics 365 is by writing plugins. In this article, we will discuss how to write a simple Dynamics 365 plugin.

What is a Plugin?

A plugin is a piece of code that can be executed in response to a specific event within Dynamics 365. Plugins can be used to extend the functionality of Dynamics 365 to fulfill business requirements that are not supported out-of-the-box. Plugins can be triggered by a wide range of events, such as when a record is created, updated, deleted, or when a workflow is executed.

Creating a New Plugin

To create a new plugin, you need to have access to Dynamics 365 Developer Toolkit, which is a Visual Studio extension. Once you have installed the toolkit, follow these steps to create a new plugin:

1. Open Visual Studio and create a new project using the Dynamics 365 Plugin Library template.

2. Give the project a meaningful name and select the appropriate target framework version.

3. Click OK to create the project.

4. In the Solution Explorer, right-click on the project and select Add New Item.

5. Select the Class template and give the class a meaningful name.

6. Click Add to add the class to the project.

7. Once the class is added, replace the placeholder code with your own code.

8. Build the project to make sure there are no errors.

9. Finally, deploy the plugin to Dynamics 365.

Writing the Plugin Code

Once you have created the plugin project, you need to write the plugin code. Here is a sample code that demonstrates how to specify the event that triggers the plugin, access the entity record that the plugin is processing, and modify the record.

using Microsoft.Xrm.Sdk;

namespace SimplePlugin
public class SimplePlugin : IPlugin
public void Execute(IServiceProvider serviceProvider)
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] is Entity)
Entity entity = (Entity)context.InputParameters[“Target”];
entity.Attributes[“new_field”] = “Hello World!”;

In this example, the plugin is triggered when a record is updated. The code accesses the updated record and adds a new field with the value “Hello World!”

Deploying the Plugin

Once the plugin code is written, it needs to be deployed to Dynamics 365. Here are the steps to deploy the plugin:

1. Build the project to create the DLL file.

2. Open Dynamics 365 and navigate to Settings > Customizations > Developer Resources.

3. Click on the Import button to import the DLL file.

4. Follow the import wizard to upload the DLL file.

5. Once the DLL file is uploaded, navigate to Settings > Customizations > Customize the System.

6. Select the entity that you want the plugin to run on.

7. Navigate to the Plug-in Steps tab and click on the New button.

8. Fill in the details of the plugin step, such as the message, primary entity, and the DLL file name.

9. Click on the Register button to register the plugin.


Writing a simple Dynamics 365 plugin is not a difficult task. However, it requires some basic knowledge of C# programming and Dynamics 365 development. In this article, we have discussed how to create a new plugin project, write the plugin code, and deploy the plugin to Dynamics 365. By following these steps, you can extend the functionality of Dynamics 365 to meet your organization’s specific business requirements.

Leave a Reply

Your email address will not be published. Required fields are marked *