Create a Basic Dynamics 365 Plugin
This tutorial demonstrates how to write a plugin to create a new task entity after a Contact entity has been created.
- Open Visual Studio
- Create a New Class Library.
3.Open the NuGet Package Manager and Install the following Package
Microsoft.CrmSdk.CoreAssemblies
4.Now Execute the I Plugin Interface. Make Sure You Include Microsoft.Xrm.Sdk namespace.
5.Now Add the necessary code. This involves getting the Context of which the Plugin is registered. Here we are registering the plugin on Create of a Contact Entity in Post operation. After checking if the Target Entity is Contact we create a new task entity and add provide necessary values to fields.
Now to Associate the Task to Contact Entity we need to obtain the GUID of contact.
In the regardingobjectid field of the task entity we give the entity reference by passing GUID and logical name of contact as parameters
6.Then we Obtain the service object from IOrganizationService which will create an task entity by calling service.Create(task).
7.Now Signing your Assembly and Build your Solution. A dll file will be created once you build the solution.
8.Open Plugin Registration Tool and Register new Assembly.
9.Select the dll file from the folder location.
10. After the Assembly has been registered right click on the Assembly and select register new step
11.Enter the message as “Create” and the Primary Entity as “contact”. Change the Event Pipeline Stage of Execution to “Post-operation” and click register new step.
Now Your Plugin is registered. You can Start testing by creating a new contact record in CRM and saving the record. We can see a new task is created and its is shown in the timeline of the contact.
In this tutorial I have explained how to create a basic dynamics Plugin to Create a task after a contact entity. Hope you are able to Understand
Thanks for Reading