Export (0) Print
Expand All

Walkthrough: Create a New Workflow in Visual Studio

[Applies to: Microsoft Dynamics CRM 2011]

This topic shows how to create a XAML workflow using the Microsoft Visual Studio Workflow Designer. Once you have created a XAML workflow project, you can add Microsoft Dynamics CRM workflow activities to the toolbox in the workflow designer. The Microsoft.Xrm.Sdk.Workflow.dll file contains several pre-existing workflow activities that you can incorporate into your workflows.

TipTip
The Developer Toolkit for Microsoft Dynamics CRM (on-premises) provides a streamlined experience for development of custom XAML Workflows. For more information, see Create and Deploy XAML Workflows Using the Developer Toolkit.

To perform this walkthrough, you must have the following:

  • Microsoft Dynamics CRM 2011 on-premises

  • Microsoft Visual Studio 2010

  • A user account with the Deployment Administrator privilege

  • Support for declarative workflows enabled on the Microsoft Dynamics CRM server. For more information, see Custom XAML Workflows for Microsoft Dynamics CRM 2011.

  • The Microsoft.Xrm.Sdk.dll and Microsoft.Xrm.Sdk.Workflow.dll files, located in the SDK\Bin folder of the SDK download package.

  1. In Microsoft Visual Studio, on the File menu, select New, and then click Project.

  2. Under Installed Templates, expand Visual C#, and click Workflow.

  3. Click Activity Library, select .NET Framework 4, specify a name and location for your project, and then click OK.

  4. In Solution Explorer, right-click your Activity Library, and click Add Reference.

  5. Click Browse, and locate the Microsoft.Xrm.Sdk.dll and Microsoft.Xrm.Sdk.Workflow.dll files. Select these files, and add them to your project.

To add to the toolbox

  1. In the View menu select Toolbox.

  2. Right-click the General group in the toolbox and select Choose Items.

  3. Click the System.Activities Components tab.

  4. Click Browse, locate and select the Microsoft.Xrm.Sdk.Workflow.dll file, and then click Open. All Microsoft Dynamics CRM workflow activities will appear in the Choose Toolbox Items dialog box with a check mark next to their name.

  5. Click OK. The Microsoft Dynamics CRM workflow activities are now visible in the General tab of the toolbox, and can be used with the designer.

To add activities to the workflow project

  1. In the toolbox, locate the activity that you would like to add.

  2. Drag the activity into the designer (.xaml) window and drop it on the text Drop activity here. For example, drag a Workflow activity from the General group into the designer, then drag a Postpone activity into the Workflow activity.

  3. If the activity you placed in the workflow designer has a red exclamation point (!) symbol there are one or more requirements that need to be satisfied. Move the cursor over that red symbol to view the tooltip that tells you what is required.

  4. If you must set the value of a required activity property, right-click the activity and select Properties. In the field for the required property, enter a valid value or expression. For example, in the PostPone activity PostponeUntil property, enter an expression of Now.AddMinutes(5). If you were to run this workflow, the postpone activity would wait five minutes.

The next step is to add new variables in the variables designer.

Variables can hold values or references to entities used by the activities in your workflow. You can create variables for a XAML workflow in Visual Studio by using the variables designer.

To add and configure variables

  1. At the bottom left corner of the workflow designer, click Variables.

  2. In the workflow designer select an activity, and then in the variables designer, click Create Variable.

  3. In the Name column, type a name for the variable.

  4. In the Variable type column, choose the appropriate type for the variable. If the type is not represented, click Browse for Types. The Browse and Select a .Net Type dialog box displays available type by DLL, and not by namespace.

  5. In the Scope column, click the appropriate scope for the variable.

  6. In the Default Value column, select a default value for the variable. This is either a literal value or a Microsoft Visual Basic .NET expression that resolves to an appropriate value at run time. The variable will be initialized to this value when the workflow is executed. Surround a string value with double quotes “”.

    For example, use the following values for the variable: now (Name), System.DateTime (Variable type), Workflow (Scope), DateTime.Now (Default).

You should be able to build the workflow by selecting Build Solution in the Build menu. If you receive build errors, check the project’s properties to make sure that the target framework is set to .NET Framework 4 and not .NET Framework 4 Client Profile.

After completing this walkthrough the workflow must be packaged into a Microsoft Dynamics CRM solution and imported into the server for you to be able to execute the workflow. This is covered in the next walkthrough Walkthrough: Modify an Existing Workflow in Visual Studio.

Microsoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.

Community Additions

Show:
© 2014 Microsoft