Skip to content

Tutorial 1

PhuocLe edited this page Mar 6, 2018 · 25 revisions

Task

  • Account Name always uppercase and don't allow user edit it.

Coding

  1. Add PL.DynamicsCrm.DevKit > 15. C# Shared Project to solution.
    • PL.DynamicsCrm.DevKit created shared project name: Wooow.Kool.Shared
  2. Add PL.DynamicsCrm.DevKit > 14. C# Plugin Project to solution.
    • A popup form opened.
    • Click button >< (right of Project Name) to create a Dynamics 365 connection. After connected. Click OK to confirm used this connection.
      • PL.DynamicsCrm.DevKit loaded all entities and bind to dropdown project name.
    • Select Account in the project name dropdown.
    • Select Crm Sdk Version
      • PL.DynamicsCrm.DevKit get all Microsoft.CrmSdk.CoreAssemblies version from NuGet
      • Click right button >< to make default select.
    • Select .Net version
      • 4.5.2 or 4.6.2
      • Click right button >< to make default select.
    • Click OK
    • PL.DynamicsCrm.DevKit created plugin project name: Wooow.Kool.Plugin.Account
  3. Rebuild solution to restore NugGet packages and check solution rebuild all succeeded.
  4. Add PL.DynamicsCrm.DevKit > 08. C# Plugin Class to project Wooow.Kool.Plugin.Account
    • A popup form opened.
    • Select saved connection or create new connection.
      • PL.DynamicsCrm.DevKit load all messages plugin for entity Account and bind to dropdown Message.
    • Select Message: Create - Stage: PreOperation. (It automatic selected Synchronous execution and not allow you change)
    • Click OK
    • PL.DynamicsCrm.DevKit created plugin class: PreAccountCreateSynchronous
  5. Rebuild solution and received errors.
  6. Add PL.DynamicsCrm.DevKit > 20. C# PluginCore.cs to Lib folder of Wooow.Kool.Shared project.
  7. Back to PreAccountCreateSynchronous class and add missing using.
  8. Rebuild solution without errors.
  9. Open Windows Explorer, go to current solution folder, then goto packages\tools\PL.DynamicsCrm.DevKit.Cli.[version] folder. Copy file: PL.DynamicsCrm.DevKit.Cli.json to solution root folder.
  10. Check solution root folder and you see 2 files: PL.DynamicsCrm.DevKit.json and PL.DynamicsCrm.DevKit.Cli.json
  11. Open file PL.DynamicsCrm.DevKit.Cli.json by Notepad and edit these information in section: plugins.profile = "DEBUG"
    • plugins.solution = "Kool"
    • plugins.includefiles = "Wooow.*.dll"
  12. Open command-line, go to Wooow.Kool.Plugin.Account folder, then run deploy.bat and waiting PL.DynamicsCrm.DevKit.Cli deploy to Dynamics Crm.
  13. Open Plugin Registration Tool and verify plugin deployed or not !
  14. Open Crm solution Kool and verify plugin Wooow.Kool.Plugin.Account added to Plug-in Assemblies node and step Wooow.Kool.Plugin.Account.PreAccountCreateSynchronous added to Sdk Message Processing Steps node.
  15. Add PL.DynamicsCrm.DevKit > 21. C# Late Bound Class to Entities folder of Wooow.Kool.Shared project.
    • A popup form opened.
    • Select saved connection or create new connection.
      • PL.DynamicsCrm.DevKit load all entities and bind to dropdown Class.
    • Select Account in the class dropdown.
    • Click OK and waiting. 2 files generated.
      • Account.cs you can edit/update your code here because it is a partial class.
      • Account.generated.cs DON'T changes this file, it lost when you re-generated Account entity.
  16. Rebuild solution and get an error missing *EntityBase class
  17. Add PL.DynamicsCrm.DevKit > 22. C# EntityBase.cs to Lib folder of Wooow.Kool.Shared project.
  18. Rebuild solution without errors.
  19. Back to class: PreAccountCreateSynchronous and beginning code here
    • Always remember check the comment section in the plugin class that PL.DynamicsCrm.DevKit help you for InputParameters and OutputParameters. It help you known the Key and Data Type.
    • Go to line 30, remove comment code, edit fixed it like below
var target = (Entity)Plugin.Context.InputParameters["Target"];
  1. Continue write your code
//YOUR PLUGIN-CODE GO HERE
var account = new Account(target);
if (account.Name != null)
    account.Name = account.Name.ToUpper();
  1. run deploy.bat again to deploy new code to your Dynamics Crm.
  2. Go to Dynamics Crm test by create Account.
  3. Check-in all files to your source control.
  4. You finished this tutorial.

Your Solution Explorer after you finished this tutorial

Finished Tutorial 1

Clone this wiki locally