Sample Plugin using Developer Toolkit

Will see a simple example, to develop and deploy plugin in CRM Online 2013 using SDK Developer Tool Kit in Visual Studio 2012.

Task: On Post Create of Account, Task should create.

Solution:

If you do not have Developer Tool Kit on your Visual Studio, Click Here to know about Installation process.

Step 1: Open Visual Studio 2012.  Click on New Project. Goto Visual C# -> Dynamics CRM -> Dynamics CRM 2013 Package. Provide Name “CrmPackage”.

This package is helpful for Deploying Plugin from Visual Studio.

New Project

Step 2: Please follow the below steps,

  1. Provide Discovery details of your organization. (I am using CRM Online 2013)
    Get this details going to CRM Web Client,
    Microsoft Dynamics CRM -> Settings -> Customizations -> Developer Resources -> Discovery Service.
  2. Select Protocol to HTTPS and click on Connect.
  3. Provide User name & Password and click on Log on.
  4. After successful login to CRM, select Organization and Solution Name. (I have Created a Separate Solution called Plugins for demo)

Step 2

Step 3: Right Click on Solution ‘CrmPackage’ (1 project) and Select Dynamics CRM 2013 Plug-in Library. Provide Name as “PostAccountCreate” and click ok.

Step 3

Step 4: On the Left Hand Side, we can see CRM Explorer. Goto Microsoft -> Entities -> Account -> Create Plug-in.

Step 4

Step 5: Select Message, Run in Context, Pipeline Stage and Execution Mode as mentioned below. Click OK.

Step 5

Step 6: You may see the below alert, click on Yes to All

Step 6

Step 7: Have to provide Strong Key to the Plugin. For that Go to Solution Explorer on the right hand side, Right Click On “PostAccountCreate” and click on Properties .

Step 7

Step 8: Follow the below steps for Strong Key set up.

  1. Go to Signing and Select Sign the assembly.
  2. Choose a strong name key file: to <New…>.
  3. Provide Key file name: as “PostAccountCreate” and uncheck the Protect my key file with a password.
  4. Select Signature Algorithm.

Step 8

Step 9: Goto Solution Explorer, double click on “PostAccountCreate.cs” file. You can see the below code,

Step 9

Step 10: Copy and paste the below code in method ExecutePostAccountCreate after //TODO: Implement your custom Plug-in business logic.

// TODO: Implement your custom Plug-in business logic.

IPluginExecutionContext context = localContext.PluginExecutionContext;
IOrganizationService service = localContext.OrganizationService;
ITracingService tracingService = localContext.TracingService;

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "account")
{
try
{
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.AddDays(7);
followup["scheduledend"] = DateTime.Now.AddDays(7);
followup["category"] = context.PrimaryEntityName;

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

followup["regardingobjectid"] = new EntityReference(regardingobjectidType, regardingobjectid);
}

// Create the task in Microsoft Dynamics CRM.
tracingService.Trace("FollowupPlugin: Creating the task activity.");
service.Create(followup);
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
}

Step 11: Finally the ExecutePostAccountCreate method looks like the below,

Step 11

Step 12: Save All. Click on F6 to build the solution.

Step 13: Goto Solution Explorer, and right Click on Solution ‘CrmPackage’ (2 projects). Click on Deploy Solution to deploy into Online CRM 2013.

Step 13

Step 14: After Successful Deployment, you can check it, whether plugin registered on Account or not, by going to Plugin Registration Tool or Go to CRM Explorer on left hand side of visual studio, you can find the below

Step 14

Step 15: Create Account record in CRM Online. After Account creation, Task is created, you can check it in under Social Pane -> Activities,

Step 15

Good Luck :):):)

Developer Toolkit for Microsoft Dynamics CRM

The Developer Toolkit for Microsoft Dynamics CRM 2013 and Microsoft Dynamics CRM Online is included in the SDK package at SDK\Tools\DeveloperToolkit.

The Developer Toolkit supports creation and deployment of plug-ins, custom workflow assemblies, XAML workflows and web resources.

With the Developer Toolkit, you can do the following:

  • Easily generate strongly typed proxy classes without having to run CrmSvcUtil.exe.
  • Get access to entity and option set definitions within Visual Studio.
  • Generate plug-in code so you can immediately begin to write code for business logic.
  • Edit and register plug-ins without using the Plug-in registration tool.
  • Create new web resources or extract existing web resources, add them to your solution, edit them, and deploy changes all within Visual Studio.
  • Create and edit workflow and dialog processes from within Visual Studio.
  • Create and deploy XAML workflows in Visual Studio.
  • Get easy access to security role and field security profile information in Visual Studio.

Installation

Follow the below steps for installing Developer Toolkit, for Prerequisites Click Here

Step 1: Open SDK or if you don’t have SDK, download Latest SDK from internet.

Step 2: Goto SDK -> Tools -> DeveloperToolKit

Step 3: Close Visual Studio before installation process begins.

Step 4: Double click on CrmDeveloperToolsVS12_Installer to install it on your machine.

Step 5: After you install the Developer Toolkit, in the Microsoft Visual Studio New Project dialog box you’ll have a Dynamics CRM node under Visual C# as shown below

Developer Tool Kit

Project template options

In the Dynamics CRM node, you have the project template options shown in the following table.

Project Template Options

CRM Package project

In your new solution, the CrmPackage project is a manifest project that contains all assets to be deployed to Microsoft Dynamics CRM combined with their deployment settings. By default, the outputs from each other project are added as references to this project in so that they can be deployed to the server.

CRM Package

You can add components to the package by adding projects as a reference or by adding components under the WebResources folder.

The RegisterFile.crmregister contains registration information for plug-ins and custom workflows created by the toolkit.

Deploy your solution

Deploy your solution to the server by right-clicking CrmPackage and then clicking Deploy. You can also deploy the Solution or the CrmPackage from the Build menu.