This topic has not yet been rated Rate this topic

Create a Custom Workflow Activity

This topic describes how to create a custom workflow activity, and use it in Microsoft Dynamics CRM.

TipTip
The Developer Toolkit for Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online provides a streamlined experience for development of custom workflow activities. For more information, see Create and Deploy Workflow Libraries Using the Developer Toolkit.

In This Topic

Required Software and Assemblies

To develop Windows Workflow Foundation 4 custom activities, you must use Microsoft Visual Studio 2010, which requires Microsoft .NET Framework 4. If it is not available on your computer, Microsoft Visual Studio 2010 will install it.

The following assemblies must be added to your project. They can be found in the SDK\Bin folder in Microsoft Dynamics CRM SDK.

  • Microsoft.Xrm.Sdk.dll

  • Microsoft.Xrm.Sdk.Workflow.dll

Use the CodeActivity Workflow Base Class

To create a 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 are able to override the Execute method to produce custom functionality.

To create a custom activity that inherits from CodeActivity

  1. Start Microsoft Visual Studio 2010.

  2. On the File menu, click New, and then click Project.

  3. In the New Project dialog box, select Workflow under Visual C# in the Installed Templates pane, and then select Activity Library.

  4. Specify a name and location for the solution, and click OK.

  5. Navigate to the Project menu and select Properties. On the Application tab, specify .NET Framework 4 as the target framework.

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

  7. Delete the Activity1.xaml file in the project.

  8. Add a class file (.cs) to the project. In Solution Explorer, right-click the project, select Add, and then click Class. In the Add New Item dialog box, type a name for the class, and click Add.

  9. Open the class file, and add the following using directives:

    using System.Activities;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Workflow;
    
  10. Make the class inherit from the CodeActivity class and give it a public access modifier as shown here:

    public class SampleCustomActivity : CodeActivity
    
  11. Add functionality to the class by adding an Execute method:

    protected override void Execute(CodeActivityContext context)
    {
        //Activity code
    }
    
    

    For more information, see Add Metadata to a Custom Workflow Activity.

  12. Specify input and output parameters. For more information, seeAdd Metadata to a Custom Workflow Activity.

  13. Compile the project to create an assembly (.dll).

To view a code sample that demonstrates how to create a custom workflow activity, see Sample: Create a Custom Workflow Activity.

Specify the Name and Group Name for a Custom Workflow Activity

When you register a custom workflow activity assembly, specify the name and group name. The name property specifies the name of the workflow activity. The group name property specifies the name of the submenu added to the main menu in the Microsoft Dynamics CRM process designer. These properties link the custom workflow activity with the Microsoft Dynamics CRM process designer, so the custom activity name will appear in the user interface.

To specify the name and group name for a custom workflow activity, use the PluginType.Name and PluginType.WorkflowActivityGroupName attributes while registering the custom workflow activity assembly. For more information about registering custom workflow activities, see Register and Use a Custom Workflow Activity Assembly. If the PluginType.Name and PluginType.WorkflowActivityGroupName attributes are set to null, the custom activity is hidden from the Microsoft Dynamics CRM workflow designer and is only accessible from XAML workflows.

If you are using the Plug-in Registration tool to register the custom workflow activity assembly, you can specify appropriate values in the Name and WorkflowActivityGroupName boxes, under the Editable region. For more information aboutusing the Plug-in Registration tool, see Walkthrough: Register a Plug-in Using the Plug-in Registration Tool.

Specify the Group Name and Name while registering

After this custom workflow activity is registered, you can use it from the Microsoft Dynamics CRM process designer for workflows or dialogs. For more information, seeRegister and Use a Custom Workflow Activity Assembly.

See Also

Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online
Send comments about this topic to Microsoft.
© 2011 Microsoft Corporation. All rights reserved.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
A couple gotchas
Make sure you set your class access modifier to "public." By default, adding a class file to the project will not include an access modifier, and by default, no access modifier means internal and you won't be able to register your plugin.

Also, change the .NET target in the project properties from ".NET Framework 4 Client Profile" to ".NET Framework 4" or you will get build errors from the using statements that state that "Xrm" is not found in the Microsoft namespace.