Share via


Designing the Registration Approval Workflow

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The registration approval workflow that is located in Contoso.TrainingMangement.Workflows is a sequential workflow. Sequential workflows are similar to flowcharts. Activities occur one after the other, from beginning to end. Like flowcharts, sequential workflows can contain branches and loops. The registration approval workflow is created with the Visual Studio workflow designer. By using the workflow designer, you can specify activities that must occur in a particular sequence, in addition to identifying decision points and process loops.

The Workflow.Designer.cs file contains the code that corresponds to the property settings and sequence of activities that are depicted in the designer. Never directly edit this code; instead, use the designer to change the workflow. The SharePoint framework provides built-in functionality that connects SharePoint tasks to Windows Workflow Foundation workflows. Figure 1 illustrates the registration approval workflow.

Ff647736.WorkflowDiagram_v1(en-us,PandP.10).png

Figure 1
The registration approval workflow

The approval workflow includes the following activity types:

  • Event activities. Event activities are initiated by the SharePoint runtime when specific external input is received by the workflow runtime. Examples include OnWorkflowActivated and OnRegistrationChanged. Event activities can respond to external user actions such as user input. SharePoint has a predefined set of events that it will raise as event activities.
  • Workflow-initiated activities. Some activities are initiated by the workflow engine whenever they are enabled by the control state of the workflow. Types of workflow-initiated activities in the approval workflow include CreateTask, CompleteTask, DeleteTask, and ExecuteCode activities.
  • Control-flow activities. The Training Management workflow includes some activities that control the flow of activities. Examples include the While activity for looping and the IfElseApprovalActivity for branching.

The workflow diagram in the Visual Studio designer uses colors and special icons to visually distinguish these types of activities. The following icons are used:

  • Green oblongs. These are for events.
  • Blue oblongs. These are for tasks that include SharePoint functionality.
  • Grey oblongs. These are for tasks that include only custom code.

As illustrated in the workflow diagram, the approval workflow proceeds as follows:

  1. onWorkflowActivated is the initial event. The workflow is instantiated by SharePoint when a user registers for a course. This is also when the initial event is raised. The Training Management application does not have a programmer-provided handler for this activity.
  2. createManagerApprovalTask invokes the code that creates an approval task and configures the fields. The approval task is added to the RegistrationApprovalTasks list and appears in the dashboard of the manager who authorizes the class registration. This code also performs housekeeping functions such as creating the unique identifier that identifies this task.
  3. whileActivity is a looping activity. The while loop accepts onRegistrationChanged events until a programmer-provided termination condition is met. The onRegistrationChanged event is the event that is raised by SharePoint whenever a registration list item changes. If the manager approves or rejects a registration request, the handler for this event changes the data state of the workflow to terminate the loop and to enable the subsequent tasks to run.
  4. completeManagerApprovalTask does not have application code associated with it. Instead, because of the type of activity (CompleteTask), SharePoint automatically changes the status of the list item task to Completed.
  5. deleteManagerApprovalTask does not have application code associated with it. It uses built-in SharePoint functionality for housekeeping.
  6. ifElseApprovalActivity is a conditional branch point in the workflow. If the manager approves the registration request, the left branch is taken to create accounting entries. If the manager rejects the request, no accounting activities occur. A programmer-provided method that is referenced as a property of this activity tests the condition.
  7. codeChargeAccountingActivity causes application-provided code to execute to generate accounting entries for the class registration.

For step-by-step instructions about how to create a workflow, download the Visual Studio extensions for Windows SharePoint Servicies 1.1 User Guide from MSDN. For general information about SharePoint workflows, see SharePoint Workflow Solutions on MSDN.

The Correlation Token Property

A correlation token is a unique identifier that enables mapping between the objects in a workflow and the environment that hosts the Windows Workflow Foundation workflow runtime. It is similar to an object ID. The correlation token property, named CorrelationToken, specifies the type of correlation token. The Training Management application's Registrations list has only one workflow associated with it. Whenever an item is added to the Registrations list, a new task is created with one associated workflow instance. This means that the application requires two correlation tokens. One token is for the workflow instance and is named workflowToken. The other token is for the SharePoint task and is named taskToken. Each activity in the workflow has a property that specifies its owner and correlation token. Task-related activities such as CreateTask and CompleteTask use the task token for correlation. For more information, see Correlation Tokens in Workflows on MSDN.

Code-Related Properties

Code-related properties of the workflow activities associate these activities with the code in the Training Management application. You can view these properties by selecting an activity in the workflow designer. These properties are the following:

  • Invoked. Event activities use the Invoked property to specify the code that should run when the event occurs. For example, an event can occur when an employee registers for a course.
  • MethodInvoking. SharePoint workflow–initiated activities use this property to specify the method that contains the application logic associated with this task.
  • ExecuteCode. Similar to the MethodInvoking property, the ExecuteCode property specifies a method to be executed. This property is not used by activity types provided by SharePoint; it is found on the Code activity provided by Windows Workflow Foundation.
  • Condition. This property is used with While and IfThen activities. It designates the method that controls the branching logic. For example, it designates when a while loop should end.
Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Footer image

To provide feedback, get assistance, or download additional, please visit the SharePoint Guidance Community Web site.

Copyright © 2008 by Microsoft Corporation. All rights reserved.