Welcome to Dynamics in Motion

Unraveling the Basics of Dynamics 365 Plugin Development: A Comprehensive Guide for Beginners

Unraveling the Basics of Dynamics 365 Plugin Development: A Comprehensive Guide for Beginners

Title: Understanding and Writing a Simple Dynamics 365 Plugin: A Beginners Guide


Welcome to your easy-to-follow guide for writing a simple Dynamics 365 plugin. This powerful tool allows businesses to customise and extend their Microsoft Dynamics 365 environment. If you’ve been overwhelmed by technical jargon, this blog will simplify the process and usher you into the world of Dynamics 365 plugins.

What is a Dynamics 365 Plugin?

The Microsoft Dynamics 365 platform facilitates plugins, which are essentially custom business logic codes that modify the system’s standard behaviour. This ensures businesses have an adaptable system that can be modified to meet specific requirements.

Why Write a Plugin in Dynamics 365?

Plugins offer unrivalled flexibility. They allow developers to introduce customised business processes hence enhancing efficiency. By seamlessly integrating with Dynamics 365, plugins ensure streamlined operations and enhanced customer experience.

Understanding The Structure of a Dynamics 365 Plugin

Before diving into the technicalities of writing a plugin, it’s essential to comprehend its structural framework. A Dynamics 365 plugin commonly has three parts:
1. Registration – registers the plugin assembly with Microsoft Dynamics 365.
2. Development – involves writing the plugin class containing the custom business logic.
3. Debugging – test and troubleshoot the plugin.

How to Write a Simple Dynamics 365 Plugin

Now, let’s delve into writing a simple Dynamics 365 plugin.

Step 1: Setup a Development Environment

Start by setting up your development environment. You’ll need Visual Studio, a powerful code editor, and the Dynamics 365 Software Development Kit (SDK). Make sure your Dynamics 365 instance is prepared for plugin development.

Step 2: Create a New Project

Open Visual Studio, click on ‘File’-> ‘New’-> ‘Project’. In the new project window, choose ‘Class Library’ and name your project.

Step 3: Adding References

In the Solution Explorer window, right-click ‘References’ -> ‘Add Reference’. Browse to the location of your Dynamics 365 SDK, select the following DLL files – Microsoft.Xrm.Sdk.dll and Microsoft.Crm.Sdk.Proxy.dll, then click on the ‘OK’ button.

Step 4: Writing Your Plugin Code

Below is a simple Dynamics 365 plugin code:

using System;
using Microsoft.Xrm.Sdk;

namespace SamplePlugin
public class SamplePlugin : IPlugin
public void Execute(IServiceProvider serviceProvider)
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] is Entity)
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters[“Target”];

// Verify that the target entity represents an account.
// If not, this plug-in was not registered correctly.
if (entity.LogicalName != “account”)

// Create a task entity.
Entity followup = new Entity(“task”);

followup[“subject”] = “Send e-mail to the new customer.”;
followup[“description”] =
“Follow up with the customer. Check if there are any new issues that need resolution.”;
followup[“scheduledstart”] = DateTime.Now;
followup[“scheduledend”] = DateTime.Now.AddDays(2);
followup[“category”] = context.PrimaryEntityName;

// Refer to the account in the task entity.
if (context.OutputParameters.Contains(“id”))
Guid regardingobjectid = new Guid(context.OutputParameters[“id”].ToString());
string regardingobjectidType = “account”;

followup[“regardingobjectid”] =
new EntityReference(regardingobjectidType, regardingobjectid);

// Obtain the organization service reference.
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

// Create the task in Microsoft Dynamics CRM.

This code creates a plugin that generates a new task every time an account entity is created.

Step 5: Build and Register Your Plugin

Once you’ve written your code, build the project, and then use the Plugin Registration Tool from the Dynamics 365 SDK to register your plugin. Remember, you can only test it in an actual Dynamics 365 environment.


Writing a Dynamics 365 plugin doesn’t have to be intimidating. With these steps, even beginners can create customised actions in their Dynamics 365 environment. Remember, plugins are instrumental tools used to enhance system functionality and customize processes, so embrace them and unlock their potential in your business processes.

Remember to adhere to best practices and thoroughly test your plugin before rolling them out into production. Happy coding!

Leave a Reply

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