Skip to content

Tutorial 5

PhuocLe edited this page Mar 8, 2018 · 10 revisions

Task

  • Automatic update latest value from Finance System to Annual Revenue field on Account.

Coding

  1. Open Crm solution Kool, then define Custom Action as below

Custom Action

  1. Add PL.DynamicsCrm.DevKit > 13. C# Custom Action Project to solution.
    • A popup form opened.
    • Select saved connection or create new connection.
    • Leave blank in the Project Name
    • Click OK
    • PL.DynamicsCrm.DevKit created custom action project name: Wooow.Kool.CustomAction
  2. Add PL.DynamicsCrm.DevKit > 09. C# Custom Action Class to Wooow.Kool.CustomAction project.
    • A popup form opened.
    • Select saved connection or create new connection.
      • PL.DynamicsCrm.DevKit load all custom action bind to dropdown Message.
    • Select wo_AnnualRevenue
    • Click OK
      • PL.DynamicsCrm.DevKit created custom action class: PostAccountwo_AnnualRevenueSynchronous
      • Always check PL.DynamicsCrm.DevKit created comment in your custom action class with InputParameters and OutputParameters

Comment

  1. Continue coding
private ParameterCollection ExecuteCustomAction()
{
    var outputs = new ParameterCollection();
    //YOUR CUSTOM ACTION BEGIN HERE
    var target = (EntityReference)Plugin.Context.InputParameters["Target"];
    var accountNumber = (string)Plugin.Context.InputParameters["AccountNumber"];
    /*
    Your code here to connect Finance System with target, accountNumber data.
    This case the result always return value: 12345
    */
    var annualRevenue = 12345;
    //Update Annual Revenue data to Account
    var account = new Account(target.Id);
    account.Revenue = annualRevenue;
    Plugin.Service.Update(account.GetUpdateEntity());
    //Return data to Custom Action
    outputs.Add(new KeyValuePair<string, object>("AnnualRevenue", annualRevenue));
    return outputs;
}
  1. Rebuild solution without errors.
  2. Open command-line, go to Wooow.Kool.CustomAction folder, then run deploy.bat and waiting PL.DynamicsCrm.DevKit.Cli deploy to Dynamics Crm.
  3. We will this custom action in this tutorial ABCD
  4. Check-in all files to your source control.
  5. You finished this tutorial.

Your Solution Explorer after you finished this tutorial

Finished Tutorial 5

Clone this wiki locally