Welcome to Dynamics in Motion

Unlocking the Power of Customization: A Beginner’s Guide to Crafting Simple Dynamics 365 Plugins

Unlocking the Power of Customization: A Beginner’s Guide to Crafting Simple Dynamics 365 Plugins

Title: Craft a Simple Dynamics 365 Plugin: A Beginner’s Guide

If you’re exploring the world of Microsoft Dynamics 365, you’ll likely come across one of its most powerful capabilities – the ability to create customised plugins. These bespoke elements can drastically enhance the functionality of the platform, tailoring it to your specific requirements. However, one might wonder how to get started with creating their first plugin. Read on as we unpack ways to write a simple Dynamics 365 Plugin in an easy and comprehensive approach.

1. Understanding D365 Plugins

Dynamics 365 plugins are custom business logic (code) that you integrate seamlessly into your CRM system to provide additional functionality. Built using .NET languages such as C#, plugins intercept CRM operations and implement operations before or after the core operation. They can be triggered by Create, Update, Delete, Retrieve, Retrieve Multiple, Associate, Disassociate, and more.

2. Pre-requisites for Creating a Dynamics 365 Plugin

Before writing your first plugin, ensure you have Visual Studio installed on your machine. You will also need the Dynamics 365 Software Development Kit (SDK). Additionally, a sound understanding of C# programming basics is advantageous, although not mandatory.

3. Setting Up Your Project

Create a new Class Library project in Visual Studio. In ‘Project Properties’, set the .NET Framework version as advised in the SDK documentation.

Add references to necessary assemblies including:
– Microsoft.Xrm.Sdk
– System.Runtime.Serialization
– System.ServiceModel

These assemblies are found in the SDK bin folder. Adding these references enables your class library to interact with Dynamics 365.

4. Writing Your Plugin

Let’s start crafting a basic Dynamics 365 plugin. The plugin we’ll write triggers when creating a new account record. Its function is simple: populate the account’s description with predefined text.

Firstly, within your class file, import the Microsoft.Xrm.Sdk namespace. Then, inherit from the IPlugin interface which is the gateway to the event execution pipeline. Next, implement the Execute method (this forms the crux of your plugin).

Your code should look something like this:

using System;
using Microsoft.Xrm.Sdk;

public class AccountCreatePlugin : IPlugin
public void Execute(IServiceProvider serviceProvider)
// …


Within the Execute method, you’ll get essential services using the serviceProvider argument. The most critical service is the IPluginExecutionContext, providing details about the context in which the plugin is triggered.

Here’s how to retrieve it:

// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

Other essential services include IOrganizationService (for interacting with Dynamics 365 data) andITracingService (for debug information).

You’ll have to check the context if it’s a ‘Create’ operation for an ‘account’ entity. If positive, you’ll proceed to set our predefined text to the account’s description.

5. Registering Your Plugin

Once you’ve written and built your plugin, the last step is to register it in your Dynamics 365 CRM. This can be accomplished utilising the Plugin Registration Tool in SDK.

Essentially you:
– Connect the tool to your CRM instance
– Register a new assembly (your DLL file)
– Register a new step that causes your plugin to trigger

Remember, your plugin triggers when a new account record is created, so set the step correctly:

– Message: Create
– Primary Entity: account

With these steps, you’re all set with your first simple Dynamics 365 Plugin!


Creating custom plugins in Dynamics 365, while initially appearing complex, can become a straightforward, manageable process. By harnessing the power of Visual Studio, C#, and the Dynamics 365 SDK, you can significantly tailor and enhance your CRM’s functionality. The world of Dynamics 365 is a vast one, ready to be explored. So, delve right in and make your experience count!

Remember, as with all code, testing is crucial. Ensure that your plugin operates flawlessly throughout different scenarios before deploying it to production environments!

Leave a Reply

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