Workflow in SharePoint 2007

Windows Workflow Foundation is a facility that allows for bookmarked, resumable applications and supports integration with SharePoint.


March 13, 2007
URL:http://www.drdobbs.com/windows/workflow-in-sharepoint-2007/198000510

Kevin is a Research Developer at Liquidnet, an equities trading system, where he has been researching Web 2.0, social software, and .NET 3.0. He can be contacted at [email protected].


Microsoft's .NET Framework 3.0 includes functionality and code libraries that could arguably be some of the most powerful advances in programming languages and development environments in recent history. Windows Presentation Foundation (WPF) provides for resolution-independent 2D and 3D declarative programming. Windows Communication Foundation (WCF) is an extremely powerful networking stack that can be used for everything from consuming and publishing web services to participating in peer networks over the Internet. Last but not least is the Windows Workflow Foundation (WF).

Windows Workflow Foundation is a facility that allows for bookmarked, resumable applications. By this I mean that, if coded properly, you can create workflow applications that can be stopped at any time and resumed at an arbitrary time in the future and can even be resumed from an arbitrary location, not necessarily the same workstation or client that initiated the workflow.

WF provides for two fundamental types of workflows:

The core of the WF is the "activity"—a piece of code that executes at the behest of the workflow runtime, within the workflow environment. Applications made up of individual, resumable activities are called "Workflow Applications" and are represented either by C# classes or a combination of C# classes and XOML (basically XAML for workflows) files. Services such as tracking and persistence can be added to a workflow engine so that you can pick up a workflow where it left off as well as keep track of every important event during the lifetime of a workflow application.

For a great book on WF, check out Dharma Shukla and Bob Schmidt's Essential Windows Workflow Foundation (Addison-Wesley Professional, 2006). If you plan on doing any serious workflow work with SharePoint, this book is mandatory reading.

So how does this all apply to SharePoint? The newest version of Windows SharePoint—the free add-on to Windows Server 2003 that offers basic web portal and intranet functionality (www.microsoft.com/technet/windowsserver/sharepoint/)—comes with powerful features, including integration with the Workflow Foundation. As far as end users are concerned, SharePoint's integration with WF is what lets them start an Approval Workflow or a Feedback Collection Workflow. If users want to collect feedback on a specific document, they can start a workflow on that document that controls SharePoint's behavior and accepts input that will be stored on workflow-bound tasks.

Developers, on the other hand, should have a far more in-depth knowledge of how WF integrates with SharePoint and what you can do with it. There are several scenarios that developers should be aware of when considering WF applications and SharePoint:

In this article, I introduce you to WF with SharePoint and give you some places to start your own learning and experimenting. WF is a huge topic, and WF's integration with SharePoint is a topic almost as big. Here, I provide an overview of each of the developer scenarios and information on where you can go to get more detail.

SharePoint Designer 2007

To create a workflow in Microsoft Office SharePoint Designer 2007, open SharePoint Designer, click File, then click New, and finally click Workflow. This brings up the Workflow design wizard. Using this wizard, you can define the input fields the workflow will collect from users when the workflow is initiated, and much more. Figure 1 shows the first step of the Workflow designer.

[Click image to view at full size]

Figure 1: The first step of the Workflow designer.

After clicking the Initiation button to define the data that users will supply to the workflow to start up (such as the list of potential reviewers or other initial data) and the Variables button to manipulate the Workflow local variables, you click Next to begin defining the individual steps involved in your custom workflow. This step will create a new task in the specified task list called "Sample Task" and will assign it to the user who initiated the workflow (which is also the user who created the workflow-specific task).

SharePoint Workflows and Visual Studio 2005

When you need Workflows that will have a larger impact than single-instance workflows, you won't be able to use the SharePoint Designer tool. Visual Studio 2005 (with the .NET Framework 3.0 properly installed extensions) has a designer for WF applications that lets you build sequential and state machine workflows, build your own custom activities, and much more. You can utilize this functionality to build your own SharePoint workflows by downloading a toolkit from Microsoft.

The SharePoint Server 2007 SDK includes the updated SDK as well as the Enterprise Content Management (ECM) Starter Kit. Included in the ECM starter kit are Visual Studio 2005 templates for creating SharePoint-specific sequential and state-machine workflows. In addition, the starter kit includes sample code for many different kinds of workflow scenarios.

Workflow Classes

While editing workflows using Visual Studio 2005 or SharePoint Designer might be helpful, many developers will want direct access to the Workflows that are running within the context of Windows SharePoint Services list items. This can be accomplished by code running on the SharePoint server through the SPWorkflow class, the entry point into the SharePoint-specific implementation of Windows Workflow Foundation. The following is a list of a few of the properties of the SPWorkflow class that can be queried at runtime by developers:

Some other useful classes include the SPWorkflowTemplateCollection class, which represents the list of workflow templates installed on a given site. The SPWorkflowTemplate class represents a single workflow template. Remember that a workflow template is the definition of the structure of the workflow, while an instance of a workflow is a running copy of that template. Finally, one of the most powerful SharePoint workflow classes is the SPWorkflowManager class that can start, run, or cancel workflows and query the list of active workflows running for a given item. All of these classes are documented in the WSS SDK available online at msdn2.microsoft.com/en-us/library/aa902527.aspx.

The Workflow Web Service

The Workflow web service that ships with SharePoint is at once an incredibly powerful tool and quite possibly one of the most frustrating web services written. The workflow.asmx web service is used by client applications such as Office to determine if there are any outstanding tasks for a server-side document when that document is opened in Word or Excel or any other Office application. If there are outstanding tasks assigned to users who are viewing a document that has an active workflow, then those tasks appear below the ribbon in the Office client application. From there, the user can interact with the Office client to complete the workflow or advance it to the next step.

The difficulty with using the workflow.asmx web service is that many of the method parameters require intimate knowledge of the XML schema for the workflow itself. You can find some of the workflow data for installed workflows in the directory. Hopefully, if you are using this web service, you are using it as a client to a workflow that you created and you won't have to worry too much about the schema for the Workflow data and form parameters.

Conclusion

I've always been of the opinion that a good design is a design that you don't notice. The integration of WF with SharePoint is (in most cases) so seamless that end users don't notice that they're using a product that ships separately from SharePoint. In addition to the end-user experience, developers have a wide range of options for dealing with workflows in SharePoint. Regardless of your ultimate goal, if you are a SharePoint developer, then you can benefit immediately from learning the Workflow Foundation and experimenting with SharePoint's integration with Microsoft's powerful new framework.

Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.