Develop a custom workflow activity step by step

Understanding Custom Workflow Activities

  • OOB Workflows are limited in functionality which can be used for a limited set of activities.
  • OOB workflows in Dynamics Customer Engagement(CRM) can be extended by writing custom code.
  • You can write custom workflow activities in Microsoft Visual C# or Microsoft Visual Basic .NET code.
  • You can develop a custom activity by creating an assembly that contains one or more classes derived from the Windows Workflow Foundation  CodeActivity class.

Develop Custom Workflow activities

  • Create custom workflow Class
  • Register custom workflow activity
  • Debug custom workflow Activity

Create a class that inherits from the CodeActivity workflow base class. This class is available in the System.Activities namespace.

Activities that inherit from the CodeActivity class can override the Execute method to produce custom functionality.

Add references to the Microsoft.Xrm.Sdk.dll and Microsoft.Xrm.Workflow.dll assemblies.

Write A Custom Activity

  • Create a class that inherits from the CodeActivityworkflow base class. This class is available in the System.Activities namespace.
  • Activities that inherit from the CodeActivityclass can override the Execute method to produce custom functionality.
  • Add references to the Microsoft.Xrm.Sdk.dlland Microsoft.Xrm.Workflow.dll assemblies.

Input and Output Parameters

Microsoft Dynamics Customer Engagement(CRM) supports two types of parameters for a workflow activity:
Input Parameters
The input parameter is annotated with the .NET attribute “Input”.
Output Parameters
The output parameter is annotated with the .NET attribute “Output”

Input Parameters

Decimal
[Input(“Decimal input”)]
[Output(“Decimal output”)]
[Default(“20.75”)]
public InOutArgument Decimal { get; set; }

Output Parameters

[Output(“Credit Score”)]
[AttributeTarget(CustomEntity, “new_creditscore”)]
public OutArgument CreditScore {get;set;}

Sample Code

Dynamic CRM -customworkflow-Magnifez Technologies

Register custom Activity

Custom workflow activity assemblies are registered using the Plug-in Registration tool.
When registering a custom workflow activity assembly Customer Engagement(CRM) Online, you must register the assembly in the sandbox (partial trust).
This process is similar to registering a plug-in.
The custom workflow activity can then be incorporated into a workflow or dialog in the Process form in Microsoft Dynamics Customer Engagement(CRM).

Debug A Custom Activity Assembly

Debugging a Custom Activity Assembly is the same debugging Plugin assembly.
The assembly can be deployed as on-disk or stored in the database.
The recommended deployment is in the database, but for debugging you should select on-disk.

Debug A Custom Activity Assembly

Step 1: Copy *.pdb and *.dll file of the activity to the bin folder of the server: %installdir%\server\bin\assembly folder.
Step 2: Attach the debugger to the CrmAsyncService.exe process.
Step 3: Test the functionality of the activity by running the workflow.

Note:

Make sure that you remove the .pdb file when you’ve finished debugging because it uses memory to have it loaded.

Understanding Custom Workflow Activities

  • OOB Workflows are limited in functionality which can be used for limited set of activities.
  • OOB workflows in Dynamics CRM can be extended by writing custom code.
  • You can write custom workflow activities in Microsoft Visual C# or Microsoft Visual Basic .NET code.
  • You can develop a custom activity by creating an assembly that contains one or more classes derived from the Windows Workflow Foundation  CodeActivity class.

Develop Custom Workflow activities

  • Create custom workflow Class
  • Register custom workflow activity
  • Debug custom workflow Activity

Create a class that inherits from the CodeActivity workflow base class. This class is available in the System.Activities namespace.

Activities that inherit from the CodeActivity class can override the Execute method to produce custom functionality.

Add references to the Microsoft.Xrm.Sdk.dll and Microsoft.Xrm.Workflow.dll assemblies.

Write A Custom Activity

  • Create a class that inherits from the CodeActivityworkflow base class. This class is available in the System.Activitiesnamespace.
  • Activities that inherit from the CodeActivityclass can override the Executemethod to produce custom functionality.
  • Add references to the Microsoft.Xrm.Sdk.dlland Microsoft.Xrm.Workflow.dll assemblies.

Input and Output Parameters

Microsoft Dynamics CRM supports two types of parameters for a workflow activity:
Input Parameters
The input parameter is annotated with the .NET attribute “Input”.
Output Parameters
The output parameter is annotated with the .NET attribute “Output”

Input Parameters

Decimal
[Input(“Decimal input”)]
[Output(“Decimal output”)]
[Default(“20.75”)]
public InOutArgument Decimal { get; set; }

Output Parameters

[Output(“Credit Score”)]
[AttributeTarget(CustomEntity, “new_creditscore”)]
public OutArgument CreditScore {get;set;}

Sample Code

Dynamic CRM -customworkflow-Magnifez Technologies

Register custom Activity

Custom workflow activity assemblies are registered using Plug-in Registration tool.
When registering a custom workflow activity assembly CRM Online, you must register the assembly in the sandbox (partial trust).
This process is similar to registering a plug-in.
The custom workflow activity can then be incorporated into a workflow or dialog in the Process form in Microsoft Dynamics CRM.

Debug A Custom Activity Assembly

Debugging a Custom Activity Assembly is the same debugging Plugin assembly.
The assembly can be deployed as on-disk or stored in the database.
The recommended deployment is in the database, but for debugging you should select on-disk.

Debug A Custom Activity Assembly

Step 1 : Copy *.pdb and *.dll file of the activity to the bin folder of server: %installdir%\server\bin\assembly folder.
Step 2 :  Attach the debugger to the CrmAsyncService.exe process.
Step 3 : Test the functionality of the activity by running the workflow.

Note:

Make sure that you remove the .pdb file when you’ve finished debugging because it uses memory to have it loaded.

× WhatsApp Chat with us