Windows Workflow Foundation

Windows Workflow Foundation provides a comprehensive programming model, run-time engine, and tools to manage workflow logic and applications. Microsoft Dynamics CRM workflow uses the Windows Workflow Foundation framework for its core infrastructure. The Microsoft Dynamics CRM workflow designer is unique to Microsoft Dynamics CRM, but it creates workflows for execution with Windows Workflow Foundation. Consequently, as users design workflow rules in Microsoft Dynamics CRM, they might never know that Windows Workflow Foundation is running behind the scenes. Windows Workflow Foundation, or WF for short, has been part of the Microsoft .NET Framework since version 3.0. WF is not a stand-alone application; instead it is a collection of extensible services and base classes that you can use to add workflow functionality quickly and consistently to an application.

One of the main advantages of using a standard framework like WF is that it provides a common toolset and functionality across multiple software applications. Microsoft currently uses WF in several different solutions, such as Microsoft Office SharePoint Server and, of course, Microsoft Dynamics CRM. WF will also take over the workflow services in the next version of Microsoft BizTalk Server. At this point, the main WF development tools are Microsoft Visual Studio or application-specific designers like the one found in Microsoft Dynamics CRM. However, we expect that the widespread use of WF will increase the demand for additional workflow designer tools intended for business users to create more complex workflow processes.

Activities

A workflow in WF is composed of a collection of activities. The activities included out of the box with WF are not application specific, they can apply to many different types of applications. For example, SequenceActivity is a simple activity that contains a collection of child activities that are always executed in order. The IfElseActivity is used to branch code based on a condition evaluated at run time. You might be thinking that WF activities sound very similar to the steps we defined in the Microsoft Dynamics CRM workflow designer, and for good reason. Microsoft Dynamics CRM steps map directly to Windows Workflow Foundation activities. Table 6-5 lists the steps and their corresponding activity classes.

Table 6-5. Workflow Steps and Activity Classes

Step Name

Activity Class

Stage

Microsoft.Crm.Workflow.Activities.StageActivity

Check condition

System.Workflow.Activities.IfElseActivity

Conditional branch

System.Workflow.Activities.IfElseBranchActivity

Default action

System.Workflow.Activities.IfElseBranchActivity

Wait condition

A combination of System.Workflow.Activities.WaitLoopActivity, System.Workflow.IfElseActivity, and System.Workflow.Activities.IfElseBranchActivity

Parallel wait branch

A combination of System.Workflow.Activities.WaitLoopActivity, System.Workflow.IfElseActivity, and System.Workflow.Activities.IfElseBranchActivity

Create record

Microsoft.Crm.Workflow.Activities.CreateActivity

Update record

Microsoft.Crm.Workflow.Activities.UpdateActivity

Assign record

Microsoft.Crm.Workflow.Activities.AssignActivity

Send e-mail

Microsoft.Crm.Workflow.Activities.SendEmailActivity or Microsoft.Crm.Workflow.Activities.SendEmailFromTemplateActivity

Start child workflow

Microsoft.Crm.Workflow.Activities.ChildWorkflowActivity

Change status

Microsoft.Crm.Workflow.Activities.SetStateActivity

Stop workflow

Microsoft.Crm.Workflow.Activities.StopWorkflowActivity

Any of the classes in the System.Workflow.Activities namespace are native to Windows Workflow Foundation. Classes found in the Microsoft.Crm.Workflow.Activities namespace are domain-specific classes implemented by Microsoft Dynamics CRM. As you can see, many of the steps map to custom activities that are specific to Microsoft Dynamics CRM, but all of the custom activity classes inherit from either Activity or SequenceActivity, which are exposed as public classes by Windows Workflow Foundation.

More Info

More Info

Microsoft Dynamics CRM wraps the activities listed in Table 6-5 in a custom activity called StepActivity to allow a user to assign descriptions to each step and to track the status of each step after it has executed. Although StepActivity inherits from SequenceActivity, it will typically only have a single child activity.

Dynamic Value Binding

Now that we understand activities and how they map to steps in a Microsoft Dynamics CRM workflow, the next logical topic is how the workflow designer implements dynamic value assignment across workflow steps. Once again, Windows Workflow Foundation provides a solution. As we’ll see in the next section, you can implement custom activities that can be configured in the native workflow designer. You can implement the properties on your custom activities in a special fashion to expose them for activity binding within WF and the Microsoft Dynamics CRM workflow designer. Activity binding allows properties from one activity to be bound to properties of another activity during workflow execution. We’ll explore the steps required to expose your activity’s properties to the workflow designer in the section "Custom Workflow Activities" later in this chapter.

You may have noticed that many of the dynamic values used in the workflow designer are not associated with a particular step, but instead with entities associated with the workflow in general. When you bind one of these values to an activity, the workflow designer inserts a special PolicyActivity just before the entity you are assigning a value to. PolicyActivity is a native WF class that can perform actions based on evaluating conditions. In this case the condition is generated to always evaluate to true because the PolicyActivity is only being used to populate the entity-based values immediately before the workflow step is executed and does not need to evaluate a real condition.

More Info

More Info

Windows Workflow Foundation is a complex topic to which many books are entirely dedicated. If you would like a better understanding of how WF works and how you can take advantage of the built-in classes, read Microsoft Windows Workflow Foundation Step by Step by Kenn Scribner (Microsoft Press, 2007).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset