web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Plugin Creation

(0) ShareShare
ReportReport
Posted on by

I am a newbie to MS CRM. I would like to know the detail steps of creating a plugin by using Visual Studio 2012. I have browsed through various different websites and tutorial but still very confused about it. Thanks!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    keyur7379 Profile Picture
    902 on at
    RE: Plugin Creation

    1. Open visual studio -> Must open as a Run as administrator -> Create new project -> Select Class library

    2. Right click on class library -> open property page ->

      1.  Application -> select target framework  4.5.2 (It is mandatory for Dynamic 365 2016 ).

      2. Signing -> Sign the assembly -> create certificate -> Save this configuration (Ctrl + Save).

    3. Add reference of

       1. Microsoft.Xrm.Sdk

       2. System.Runtime.Serialization

       3. System.ServiceModel

    4. Create class ex. public class DeletePriceListLineItem : IPlugin{in side your business logic code}

    5. Build your project -> Open plugin registration tool ->

    Please do this registration process as per below mentioned URL :

    https://msdn.microsoft.com/en-in/library/gg309580.aspx

    If helpful then mark as verified .

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: Plugin Creation

    Hi Mary,

    The following steps are to be performed for creating a plugin in Dynamics CRM.

    Step 1: You need to create a Visual Studio Solution. Open Visual Studio 2012. Click on New Project. Go to Visual C# -> Dynamics CRM -> Dynamics CRM 2013 Package. Provide Name "CrmPackage".

    Step 2: Connect the solution to Microsoft Dynamics CRM instance

    Step 3: Right Click on Solution 'CrmPackage' (1 project) and Select Dynamics CRM 2013 Plug-in Library.

    Step 4: In CRM Explorer on left hand side, go to Microsoft -> Entities -> Account -> Create Plug-in.

    Step 5: Select Message, Run in Context, Pipeline Stage and Execution Mode

    Step 6: Provide Strong Key to the Plugin

    Step 7: Write, save and build you plugin solution.

    For more explanation on each step, please refer the blog below. It helps you to have a simple and clear understanding of creating a sample plugin.

    https://arunpotti.wordpress.com/2014/10/04/sample-plugin-using-developer-toolkit/

    For understanding the basic event execution pipeline, refer the blog below.

    https://arunpotti.wordpress.com/2014/10/03/overview-of-plugins/

    Hope this helps you.

  • Verified answer
    Community Member Profile Picture
    on at
  • Inogic Profile Picture
    651 on at
    RE: Plugin Creation

    Below is an simple example to write plugin:

     

    Step 1:

    Create your own project of the type Class library in which you want to add your plugin class. So here in this example we have added one class “KeyPlugin.cs”.

    Step 2:

    Very important step is, you need to add plugin required DLL(s) references and reference names into your project, as they won’t be automatically added.

    using System;

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Sdk.Client;

    using Microsoft.Xrm.Sdk.Query;

    using System.ServiceModel;

    using Microsoft.Crm.Sdk.Messages;

    You will find the DLL’s in the Bin folder of CRM SDK

    Step 3:

    Once you added all references, implement the interface “IPlugin” to the class, and then add “Execute” method in which pass the “IServiceProvider” interface. See below code to get better idea.

    namespace PluginUsingClass

    {

        public class KeyPlugin : IPlugin

        {

     

            public void Execute(IServiceProvider serviceProvider)

            {

                IPluginExecutionContext pluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

                IOrganizationServiceFactory organizationServiceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

                IOrganizationService organizationService = organizationServiceFactory.CreateOrganizationService(new Guid?(pluginExecutionContext.UserId));

                ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

     

                Entity preImage = null;

                Entity postImage = null;

                Entity targetEntity = null;

     

                try

                {

                    //check if target found

                    if (pluginExecutionContext.InputParameters.Contains("Target") && pluginExecutionContext.InputParameters["Target"] is Entity)

                    {

                        //read target entity

                        targetEntity = (pluginExecutionContext.InputParameters["Target"] as Entity);

                    }

     

                    //check if pre image found

                    if (pluginExecutionContext.PreEntityImages.Contains("PreImage"))

                    {

                        //read pre image entity

                        preImage = (pluginExecutionContext.PreEntityImages["PreImage"] as Entity);

                    }

     

                    //check if post image found

                    if (pluginExecutionContext.PostEntityImages.Contains("PostImage"))

                    {

                        //read post image entity

                        postImage = (pluginExecutionContext.PostEntityImages["PostImage"] as Entity);

                    }

     

                    //Write your logic here

                }

                catch (FaultException<OrganizationServiceFault> fault)

                {

                    throw new FaultException(fault.Message);

                }

                catch (Exception ex)

                {

                    throw new InvalidPluginExecutionException(ex.Message);

                }

            }

        }

    }

     

    This is how you can create your plugin code.

    Note : Method name “Execute” is very important as this is the entry point to the plugin.

     

    Step 4:

    Now we need to Sign the assembly. For that go to Properties of the Plugin Project in Visual Studio and click on Signing then click on sign the assembly and create a new sign key.

    After that build the solution.

    Step 5:

    Now we will see how to deploy this plugin using plugin registration tool provided in the SDK.

    1. Go to your “Plugin Registration Tool” and connect with your environment.
    2. Then register with new assembly and add your step and images as per requirement.

    Thanks!

  • Community Member Profile Picture
    on at
    RE: Plugin Creation

    Hi! I know a plugin that can help log calls automatically in MS Dynamics. That app is Tenfold, a CTI and sales acceleration platform that offers features like call logging and call monitoring. You can check out Tenfold on the integrations page if you'd like to know more. www.tenfold.com/.../dynamics

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
UllrSki Profile Picture

UllrSki 2

#3
SC-08081331-0 Profile Picture

SC-08081331-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans