Tutorial 1 - phuocle/Dynamics-Crm-DevKit GitHub Wiki
Task
- Lead can be import by Excel file and make sure the topic always uppercase after lead imported
Coding
- Create a blank solution
Paz.LuckeyMonkey - Add
New Project10. C# Shared Projectto solutionPaz.LuckeyMonkeyPL.DynamicsCrm.DevKitcreated shared project name:Paz.LuckeyMonkey.Sharedwith the following folders, filesEntitiesLibDate.csEntityBase.csExtension.csPluginCore.csSimpleJson.cs
- Add
New Project03. C# Plugin Projectto solution.- A popup form
Add new Plugin Projectopened - Click button
><to create/select a Dynamics 365 connection - After connected
PL.DynamicsCrm.DevKitloaded all entities and bind to dropdownProject Name - Select
Leadin theProject Name - Select
9.0.2.4in theCrm VersionPL.DynamicsCrm.DevKitget allMicrosoft.CrmSdk.CoreAssembliesversion fromNuGet - Select
4.5.2in the.Net version - Click
OK PL.DynamicsCrm.DevKitcreated plugin project name:Paz.LuckeyMonkey.Plugin.Lead
- A popup form
- Rebuild solution to restore
NuGetpackages - Add
New Item02. C# Plugin ClasstoPaz.LuckeyMonkey.Plugin.Leadproject- A popup form opened
- Click button
><to create/select a Dynamics 365 connection PL.DynamicsCrm.DevKitload all messages plugin for entityLeadand bind to dropdownMessage- Select
Message:Create-Stage:PreOperation. (It automatic selectedSynchronousExecutionand not allow you change) - Click
OK PL.DynamicsCrm.DevKitcreated plugin class:PreLeadCreateSynchronous
- Open Windows Explorer, go to current solution folder, then goto
packages\tools\PL.DynamicsCrm.DevKit.Cli.[version]folder. Copy file:PL.DynamicsCrm.DevKit.Cli.jsontosolution root folder - Check solution root folder and you see 2 files:
PL.DynamicsCrm.DevKit.jsonandPL.DynamicsCrm.DevKit.Cli.json - Open file
PL.DynamicsCrm.DevKit.Cli.jsonby Notepad and edit these information in section:plugins.profile = "DEBUG"plugins.solution = "LuckeyMonkey"plugins.includefiles = "Paz.LuckeyMonkey.*.dll"
- Rebuild solution then
right-clickondeploy.batof projectPaz.LuckeyMonkey.Plugin.Leadthen selectExecute fileand waitingPL.DynamicsCrm.DevKit.Clideploy to Dynamics 365 - Open
Plugin Registration Tooland verify plugin deployed - Open Dynamics 365 solution
LuckeyMonkeyand verify pluginPaz.LuckeyMonkey.Plugin.Leadadded toPlug-in Assembliesnode, stepPaz.LuckeyMonkey.Plugin.Lead.PreLeadCreateSynchronousadded toSdk Message Processing Stepsnode - Add
New Item01. C# Late Bound ClasstoEntitiesfolder ofPaz.LuckeyMonkey.Sharedproject.- A popup form opened
- Click button
><to create/select a Dynamics 365 connection - After connected
PL.DynamicsCrm.DevKitload all entities and bind to dropdownClass - Select
Leadin theClass - Click
OKand waiting, 2 files generatedLead.csyou can edit/update your code here because it is a partial class.Lead.generated.csDON'T changes this file, it will be lost when you re-generateLeadentity
- Back to class:
PreLeadCreateSynchronousand edit code like bellow
private void ExecutePlugin(IPluginExecutionContext context, IOrganizationServiceFactory serviceFactory, IOrganizationService service, ITracingService tracing)
{
//var target = (???)context.InputParameters["Target"];
//var preEntity = (Entity)context.PreEntityImages["PreImage"];
//var postEntity = (Entity)context.PreEntityImages["PostImage"];
//YOUR PLUGIN-CODE GO HERE
LeadSubjectAlwaysUppercase(context, service, tracing);
}
private void LeadSubjectAlwaysUppercase(IPluginExecutionContext context, IOrganizationService service, ITracingService tracing)
{
Debugger.Trace(tracing, "BEGIN LeadSubjectAlwaysUppercase");
var target = (Entity)context.InputParameters["Target"];
var lead = new Shared.Entities.Lead(target);
if (lead.Subject != null)
{
lead.Subject = lead.Subject.ToUpper();
}
Debugger.Trace(tracing, "END LeadSubjectAlwaysUppercase");
}
Note You can replace Target with InputParameters that PL.DynamicsCrm.DevKit created comment above to get an other InputParameters
- Run
deploy.batagain to deploy new code to your Dynamics 365 - Go to Dynamics 365, do an import
Leadto check topic always uppercase after lead imported - Check-in all files to your source control
- You finished this tutorial
Summary
This tutorial, you know howto
- Add
10. C# Shared Project - Add
03. C# Plugin Project - Add
01. C# Late Bound Class - Add
02. C# Plugin Class - Config
PL.DynamicsCrm.DevKit.Cli.jsonforPlugins