Skip to content

Tutorial 3

PhuocLe edited this page Mar 7, 2018 · 8 revisions

Task

  • End user add/edit Contact record which Job Title field have text: developer, automatic send an email to: admin@xxx.yyy.com

Coding

  1. Add PL.DynamicsCrm.DevKit > 18. C# Workflow Project to solution.
    • A popup form opened.
    • Select saved connection or create new connection.
      • PL.DynamicsCrm.DevKit load all entities and bind to dropdown Project Name.
    • Select Contact
    • Click OK
    • PL.DynamicsCrm.DevKit created custom workflow project name: Wooow.Kool.Workflow.Contact
  2. Add PL.DynamicsCrm.DevKit > 10. C# Workflow Class to Wooow.Kool.Workflow.Contact project.
    • A popup form opened.
    • Enter: ValidateRegex in the Class Name
    • Click OK
    • PL.DynamicsCrm.DevKit created class: WooowKoolWorkflowContact_ValidateRegex
  3. Coding
[Input("String To Validate")]
public InArgument<string> StringToValidate { get; set; }

[Input("Match Pattern")]
public InArgument<string> MatchPattern { get; set; }

[Output("Valid")]
public OutArgument<string> Valid { get; set; }

private void ExecuteWorkflow(CodeActivityContext executionContext, IWorkflowContext workflowContext, IOrganizationServiceFactory serviceFactory, IOrganizationService service, ITracingService tracing)
{
    tracing.Trace("Begin Execute Workflow: WooowKoolWorkflowContact_ValidateRegex");

    var stringToValidate = StringToValidate.Get(executionContext);
    var matchPattern = MatchPattern.Get(executionContext);
    if (ValidateString(stringToValidate, matchPattern))
    {
        Valid.Set(executionContext, "1");
    }
    else
    {
        Valid.Set(executionContext, "0");
    }

    tracing.Trace("End Execute Workflow: WooowKoolWorkflowContact_ValidateRegex");
}

private bool ValidateString(string valString, string matchPattern)
{
    Match match = Regex.Match(valString, matchPattern, RegexOptions.IgnoreCase);
    return match.Success;
}
  1. Resolved errors and rebuild solution without errors.
  2. Open file PL.DynamicsCrm.DevKit.Cli.json by Notepad and edit these information in section: workflows.profile = "DEBUG"
    • workflows.solution = "Kool"
    • workflows.includefiles = "Wooow.*.dll"
  3. Open command-line, go to Wooow.Kool.Workflow.Contact folder, then run deploy.bat and waiting PL.DynamicsCrm.DevKit.Cli deploy to Dynamics Crm.
  4. Open Plugin Registration Tool and verify custom workflow deployed.
  5. Go to Crm, open solution Kool and create a workflow that call this custom workflow
  6. Check-in all files to your source control.
  7. You finished this tutorial.

Your Solution Explorer after you finished this tutorial

Finished Tutorial 3

Clone this wiki locally