Walkthrough: Modify an Existing Workflow in Visual Studio

[Applies to: Microsoft Dynamics CRM 2011]

In this walkthrough, you will learn how to modify a Microsoft Dynamics CRM workflow process definition (XAML) in Microsoft Visual Studio, import the modified XAML into Microsoft Dynamics CRM, and use the workflow process.

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.

In Visual Studio, you cannot open the .xaml file of the workflow process that is authored in the Microsoft Dynamics CRM process designer. You must create a Windows Workflow Foundation project, add required references to the Microsoft Dynamics CRM DLLs, and then import the .xaml file to work on it.

To perform this walkthrough, you must have the following:

  • Microsoft Dynamics CRM 2011 (on-premises)

  • 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.

In this step, you will create a sample workflow process that sends an email to a new contact when the contact is created. In this workflow process, you will add a Send Email activity and the required information to send email message to the new contact. You can find the completed workflow in the SDK download folder Walkthroughs\Workflow\XAMLWorkflowProject.

To create a workflow

  1. Log on to Microsoft Dynamics CRM.

  2. In the Navigation Pane, click Settings. Under Process Center, click Processes.

  3. Click New.

  4. In the Create Process dialog box, do the following:

    1. In the Process name box, type SendContactMail.

    2. In the Entity list, click Contact.

    3. In the Category list, click Workflow.

    4. Click OK.

  5. In the Process pane, click Add Step, and then select Send Email. Type a step description, and then click Set Properties.

  6. In the Send Email designer, set the To field to {Contact(Contact)} by following these steps:

    1. In the Send Email designer, click To.

    2. In the Form Assistant, under Look for, set both drop-down lists to Contact. Click Add, and then click OK.

  7. Add a suitable subject and message body.

  8. Click Save and Close.

In this step, you will export the process, created previously in Step 1, as part of a solution to obtain the .xaml file that contains the workflow process definition.

To export the process

  1. In Microsoft Dynamics CRM, open an existing solution or create a solution.

  2. Add the process that you created to the solution.

    1. In the Solution: <Solution_Name> dialog box, click Components.

    2. Click Add Existing, and then click Process.

    3. Locate the SendContactMail process, select it, and click OK.

    4. The Missing Required Components dialog box appears that prompts you to add the required components for the process as part of the solution. Click Yes, include required components, and then click OK.

    5. Click Save and close to save the changes and return to the solutions pane.

  3. In the solutions pane, select the solution, and then click Export.

  4. Click Publish All Customizations. After the customizations are published, click Next.

  5. On the Export Settings page, click Next.

  6. On the Package Type page, click Unmanaged, and then click Export.

  7. This initiates a download of a compressed file. In the File Download dialog box, click Save, specify a location for the file, and then save it. Save the .zip file to a known location.

Browse to the folder containing the saved .zip file, and extract or unzip the exported solution file. For example, unzip the file c:\Temp\<Solution_Name>.zip to the c:\Temp\<Solution_Name> folder. Browse to the Workflows folder under the solution folder, and locate the .xaml file for the workflow process created in step 1: SendContactMail-<Guid>.xaml.

In this step, you will use the Visual Studio workflow designer to modify the .xaml file obtained at the end of previous step. You will modify the workflow definition so that the SendMail workflow runs every three months, and send regular reminders to the contacts. You can find the completed workflow in the SDK download folder Walkthroughs\Workflow\SolutionWithUpdatedXAML.

To modify the XAML

  1. Create a XAML workflow project (Activity Library) in Microsoft Visual Studio. For instructions to do so, see Walkthrough: Create a New Workflow in Visual Studio

  2. If you have not already done so, add the Microsoft Dynamics CRM activities to the toolbox. For instructions on how to do this, see Add Microsoft Dynamics CRM Workflow Activities to the Toolbox.

  3. Add the existing .xaml file you previously created and unzipped to the project.

    1. In Solution Explorer, right-click the project, select Add, and then click Existing Item.

    2. Select XAML Files (*.xaml;*.xoml) from the file type list. Next, browse to the location where you saved the exported .xaml file from Microsoft Dynamics CRM, select it, and then click Add. For this tutorial, the .xaml file is available in the c:\temp\<Solution_Name>\Workflows folder.

  4. Double-click the .xaml file to view it in the workflow designer. Collapse the steps for the Send Email activity so that it looks like the following figure.

    XAML imported from Microsoft Dynamics CRM
  5. From the toolbox, under ControlFlow, drag a While activity into the workflow activity.

  6. From the toolbox, under ControlFlow, drag a Sequence activity into the body of the While activity.

  7. In the designer, drag the existing Send EMail activity into the Sequence activity.

  8. From the toolbox, under General, drag a Postponed activity into the Sequence activity, beneath the Send EMail activity.

  9. Right-click the Sequence activity, and then click Create Variable.

  10. In the variables designer for the Sequence activity, specify the following values:

    • Name: NextReminder

    • Variable type: System.DateTime. Click Browse for Types in the drop-down list. In Browse and Select a .Net Type, expand mscorlib, expand System, select DateTime, and then click OK.

    • Scope: Workflow

    • Default: System.DateTime.UtcNow

  11. From the toolbox, under Primitives, drag an Assign activity into the Sequence activity, between the Send Email and Postponed activities.

  12. In the To box of the Assign activity, type NextReminder. In the Enter a VB Expression box, type NextReminder.AddMonths(3) or for testing purposes use NextReminder.AddMinutes(5).

  13. Right-click the Delay activity, and then click Properties. In the Duration box, set the value to New TimeSpan(NextReminder.Ticks).

  14. For the While activity, set the Condition property to True. Your updated XAML should look like the following:

    XAML modified in Visual Studio
  15. Save the updated XAML file to a new folder by using the Save As command. For this walkthrough, save the .xaml file to the c:\UpdatedXAML folder.

  16. On the File menu, click Close Solution.

The completed workflow project is available in the Walkthroughs\Workflow\XAMLWorkflowProject folder of the SDK download.

In this step, you will import the modified XAML as part of the solution into Microsoft Dynamics CRM. You will use the exported solution files you previously unzipped to create a .zip file with the updated XAML.

To import the modified XAML

  1. Copy the updated .xaml file from the c:\UpdatedXAML folder to overwrite the existing original .xaml file in the c:\temp\<Solution_Name>\Workflows folder.

  2. Compress the c:\temp\<Solution_Name> folder to a .zip file. For example, c:\temp\<Solution_Name>.zip.

  3. Navigate your browser to the Microsoft Dynamics CRM web application.

  4. In the Navigation Pane, click Settings, under Customization, click Solutions.

  5. Click Import. On the Select Solution Package page, browse to the updated solution file, c:\temp\<Solution_Name>.zip, select it, and then click Next.

  6. On the Solution information page, verify the information, and then click Next.

  7. On the Solution Options page, click Next.

  8. On the Importing Solution page, information about the components in the imported solution is displayed. Click Publish All Customizations to publish the solution components.

  9. After the customizations are published, click Close.

  10. Click Processes in the sitemap.

  11. Select the imported workflow in the workflow list, and then click Activate.

A complete and ready to import solution of this workflow can be found in the Walkthroughs\Workflow\SolutionWithUpdatedXAML folder of the SDK download.

To Activate and Run the Workflow

  1. In the Navigation Pane, select Processes.

  2. Check the SendContactMail process, select Activate, and then click OK.

  3. On the System Jobs page, select New Record, and then click Contact. Enter the required information and be sure to give your contact a valid email address. Save the contact record.

  4. A workflow named SendContactMail will be displayed in the System Jobs list. You might have to click the refresh icon for the workflow to display.

  5. Navigate to the Activities list of your Workplace. You should see one or more emails that were created from the workflow.

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