Export (0) Print
Expand All

Chapter 7: Managing Complex Business Processes with Custom SharePoint Workflow

Office 2007

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.

This article is an excerpt from Programming Microsoft Office Business Applications by Steve Fox, Rob Barker, Paul Stubbs, Joanna Bichsel, and Erika Ehrli Cabral, from Microsoft Press(ISBN 9780735625365, copyright Microsoft Press 2008, all rights reserved). No part of these chapters may be reproduced, stored in a retrieval system, or transmitted in any form or by any means—electronic, electrostatic, mechanical, photocopying, recording, or otherwise—without the prior written permission of the publisher, except in the case of brief quotations embodied in critical articles or reviews.

Contents

Take a moment to think about all the things you do every day in your work. You may come up with a huge list of individual tasks that are directly related to your organizational responsibilities and accountabilities. You will also come to realize that you interact extensively with your peers and direct managers. If you work in a medium- or large-size company, you may also cross-collaborate with departments or groups outside of your own. All this interaction happens in many different ways. It can happen in the many e-mail messages you send and receive every day, in phone calls, during the frequent knock-on-someone-else’s door, in meetings, and in chat messages. Even when we do not realize we’re doing it, we all play roles in different business processes. We all interact and need these frequent small communication exchanges to get things done and to make the necessary decisions that keep our businesses working. However, in many cases, coordinating business processes is complicated, and employees do not collaborate in the most efficient way. Also, some business processes are quite complex in the sense that they require interaction between multiple actors and systems.

There is more to all these challenges and opportunities. While all of this out-of-band interaction takes place, we fail to update back-end systems that exist to help store information related to a business process. Sometimes we do not update systems because of all the overhead and increased work that they bring. We either get the work done or spend our time tracking metadata. Back-end systems represent a huge investment for companies, and sadly, they may be seen as overhead since they do not map to the real way that people work. In many cases, back-end systems require end users to log on to other systems to copy and paste data. The consequence: frustrated employees and slow business productivity.

Fortunately, new workflow technologies provide the option to automate and coordinate business processes. Workflows help bring together the power of human collaboration with the power of software to improve communication and task management. Workflows allow you to route specific tasks to different actors and systems. Therefore, you can streamline business processes while greatly increasing business efficiency. Additionally, workflows provide end users the ability to work productively by not requiring them to log on to all the systems in which the enterprise has invested.

The goal of this chapter is to introduce you to a new set of workflow capabilities offered by the 2007 Microsoft Office system. You will explore different Microsoft products and technologies that you can use to build custom Office Business Application (OBA) workflow solutions. Hopefully, this chapter can help you understand how to leverage your current technology investments and think about the wide variety of custom workflow solutions and architectures that you can use to optimize the efficiency of your business processes.

A workflow can be defined as a set of related tasks or activities that form an executable representation of a business process. Workflows help improve human interaction by automating individual tasks and streamlining processes.

The 2007 Microsoft Office system includes a set of applications, servers, services, and tools designed to work together to build and deploy custom workflow solutions. Additionally, you can use the Microsoft .NET Framework Windows Workflow Foundation (WF) and Microsoft Visual Studio 2008 to build powerful workflow solutions that integrate with the 2007 Microsoft Office system. Depending on your business needs, you can use different combinations of these tools and technologies to create workflow solutions that connect line-of-business (LOB) information with Office client applications. Therefore, you can provide end users with a simplified and well-known set of programs to interact with LOB data and reduce the complexity of business workflows. Figure 7-1 shows a roadmap of key developer tools and technologies you can use to create custom workflow solutions.

As a developer, you face a common question: Which set of tools and technologies should I use to build a custom solution workflow? The following sections of this chapter provide a high-level overview of the different key developer tools and technologies that you can use to build workflow-enabled applications. It also discusses advantages and disadvantages of each one to guide you to a better informed technology decision.

Figure 7-1. Roadmap of key developer tools and technologies that help create custom workflow solutions

Tools for creating workflow solutions

Windows Workflow Foundation

Windows Workflow Foundation (WF) is a platform component of the Microsoft .NET Framework 3.5. WF provides a workflow runtime engine, an extensible programming model, and tools that help build and execute workflow-enabled applications. WF allows asynchronous programming to help define persistent workflow applications. That is, you can define long-running workflows that preserve state and wait indefinitely until a user or application executes the next activity. Additionally, WF allows you to build applications that consist of one or more workflows. The workflow runtime engine executes individual activities that compose workflows one at a time and hosts the execution inside any Windows process, including console applications, Windows forms applications, Windows Services, ASP.NET Web sites, and Web services. For more information about the WF programming model, visit Windows Workflow Foundation Programming Guide.

You can use Microsoft Visual Studio 2008 to create workflow solutions using a graphic workflow designer, or you can create entire workflow solutions programmatically. Since workflows are based on activities, WF provides a Base Activity Library (BAL) that includes a set of general purpose activities that are common to workflow solutions. They include Code, Sequence, While, IFElse, and other activities that help model primitive operations that exist in different programming languages. Additionally, you can define custom activities and create custom activity libraries (CAL).

There are three main namespaces you can use to create workflows programmatically

using WF:

  • System.Workflow.Activities   Defines activities that can be added to workflows to create and run an executable representation of a work process.

  • System.Workflow.ComponentModel   Provides the base classes, interfaces, and core modeling constructs used to create activities and workflows.

  • System.Workflow.Runtime   Contains classes and interfaces you can use to control the workflow runtime engine and the execution of a workflow instance.

Figure 7-2 shows the WF components: activities, workflows, custom activity libraries, the WF runtime engine, the WF services, and the WF BAL. They are all hosted in a process that executes a workflow-enabled application.

Figure 7-2. A workflow-enabled application running on the Windows Workflow Foundation platform

Workflow-enabled application on WF platform

Workflow Authoring Styles

The WF supports two main authoring styles of workflow programs:

  • Sequential workflow   Executes activities in a predefined pattern and represents a workflow as a procession of steps that must be executed in order until the last activity is completed. This type of workflow can be modeled as a flowchart. Therefore, to design a graphical representation of a workflow, you can use flowchart structures such as start, activity, repetition, loops, and finish. A good example to explain a sequential workflow is a simple notification system. Imagine that you need to build a vacation leave notification system for your company. In this solution, the workflow starts when Valeria, an employee, opens the vacation leave notification form to define the days she plans to be away for the holidays. Once the form is complete, the employee submits the form and the system sends a notification to her manager, Monica, who reviews the summary document, assessing the number of days the employee is planning on being away. If the manager approves the document, the document is moved to an “approved document library” that backs up all time-off summary documents. Next, the system will notify the rest of the team that Valeria plans to be on vacation for the holidays. However, if the manager rejects the document, the system will notify Valeria, and she will have to review the manager’s comments attached in the form. In either case, the workflow reaches an end and terminates the execution.

  • State machine workflow   Responds to external events as they occur and represents a group of states, transitions, and events, which trigger transitions between these states. We will use a document-publishing process to explain state machine workflow. Imagine that you work for an editorial company that publishes technical articles for software developers and you are asked to build an article publishing workflow application. In this solution, the workflow starts when Hubert, a well-known contributor, submits a technical article using a Web-based publishing system. Submitting an article triggers a OnDocumentCreated event. This event calls a Web service that stores the technical article in a Microsoft Office SharePoint 2007 document library and sends an e-mail message to the corresponding subject-matter experts to ask for a technical review. The technical article will remain in a DocumentCreated state until all approvers review and approve the technical article. Once this step is completed, the system will trigger an OnDocumentApproved event. This event changes the status of the technical article to DocumentApproved and sends an e-mail message to the publisher to notify him that this particular technical article is ready for publishing. Carlos, the publisher, fills out a form specifying that this document is ready for publishing and submits the form to the printer. This will trigger an OnDocumentPublished event that changes the status of the article to DocumentPublished, after which an e-mail message is sent to the contributor notifying him that his technical article was sent to the printer. Finally, the printer logs on to the publishing system and marks the technical article as completed. This launches an OnDocumentCompleted event that changes the status of the document to DocumentCompleted and sends an e-mail message notifying all the participants in the workflow that the technical article was printed. The workflow reaches an end and terminates the execution.

Figure 7-3 shows a sequential workflow and a state machine workflow diagram.

Figure 7-3. Sequential and state machine workflow diagrams

Sequential and state machine workflows

As we explained earlier, the WF provides a workflow runtime engine, an extensible programming model, and tools that help build and execute workflow-enabled applications. However, if you want to build custom workflow solutions that integrate seamlessly with the 2007 Microsoft Office system, you can consider using the workflow services provided by Windows SharePoint Services 3.0 and Microsoft Office SharePoint Server 2007.

Windows SharePoint Services 3.0

Windows SharePoint Services 3.0 provides enhanced support to create document-oriented features and helps integrate a human dimension to custom workflow solutions. Windows SharePoint Services workflows can assign tasks to users and allow users to see status on any workflow instance. Windows SharePoint Services workflows can be added to documents, list items, or content types and are made available to users at the document library or list level.

We explained earlier that the WF runtime engine executes individual activities that compose workflows one at a time and hosts the execution inside any Windows process. In the same way, Windows SharePoint Services can also act as a host for the WF runtime engine. Windows SharePoint Services supports the WF runtime engine and WF services. However, it provides a different programming model. The Microsoft.SharePoint.Workflow namespace inherits many of the classes from the System.Workflow namespace and provides a new set of classes, interfaces, and enumerations that represent the workflow functionality contained in Windows SharePoint Services. For more information, seeMicrosoft.SharePoint.Workflow.

An important item to consider while designing workflow OBAs is the tools you can use to create them. You can create custom workflow OBA solutions using Microsoft SharePoint Designer 2007 or the workflow designer in Visual Studio 2008. The last section of this chapter explains how to create custom workflow OBAs using these tools.

In Windows SharePoint Services, a workflow that is running on a specific item is a workflow instance, and workflow templates are workflow programs that are available on a site, list, or content type. Association is the process of binding a workflow template to a site, list, or content type. Workflows can be associated to servers or Web forms running Windows SharePoint Services.

Figure 7-4 shows the workflow architecture in Windows SharePoint Services 3.0.

Figure 7-4. Workflow architecture in Windows SharePoint Services 3.0

Windows SharePoint Services workflow architecture

Workflow templates may or may not have workflow input forms. These forms allow end users to interact with workflows and can be of four different kinds.

  • Association form   Allows site administrators to capture general parameter settings for a workflow, such as the name of the workflow and the association of the workflow with a specific list, document library, or content type.

  • Initiation form   Allows end users to specify or override options when a workflow instance starts. A workflow can be initiated either as the result of a manual action by the end user or triggered from an event. This form is presented to the user only when a workflow is started manually.

  • Task form   Allows end users to specify the details of tasks assigned to them.

  • Modification form   Allows users to define new tasks or delegate the task to a different end user.

Windows SharePoint Services defines the previous forms as ASP.NET 2.0 pages. While designing OBAs, you have the option to create custom ASP.NET 2.0 Web forms to define the behavior you need for association, initiation, task, and modification forms. Additionally, you can use custom forms to control the Web design of the forms. For example, you can configure a set of forms using your company logo and Web site style sheets. You can use master pages in custom association, initiation, task, and modification forms to display the same user interface you use for your internal Web sites.

Windows SharePoint Services provides a set of definition and configuration files that contain the information necessary to create a workflow template and instantiate workflows. These files can be represented by different combinations of files, including an XML markup file that includes the declarative metadata of the workflow, in combination with a code-behind file that contains custom code representing the properties and behavior of the workflow.

The workflow definition schema allows you to define multiple settings such as the name, GUID, description, and URLS for custom forms, the name of the workflow assembly and class, and custom metadata of the workflow. Listing 7-1 shows a sample XML markup file for an Expense reporting solution. Note how the AssociationURL, InititiationURL, and ModificationURL attributes of the workflow element define the custom forms that this workflow solution uses for association, instantiation, and modification, respectively.

Listing 7-1. This is an example of an XML markup file for an expense report solution

<?xml version=“1.0” encoding=“utf-8” ?>
<Elements xmlns=“http://schemas.microsoft.com/sharepoint/”>
    <Workflow
        Name=“ExpenseReportWorkflow”
        Description=“Use this workflow to track expense report status.”
        Id=“C6964BFF-BG8D-41ac-AC5E-B61EC111731C”
        CodeBesideClass=“OBAExpenseReport.Workflow1”
        CodeBesideAssembly=“OBAExpenseReport, Version=12.0.0.0, Culture=neutral,
        PublicKeyToken=71e3bce121e9429c”
        TaskListContentTypeId=“0x01080100C9C9515DE4E24001905074F980F93160”
        AssociationUrl=“_layouts/expenseReportAssociationPage.aspx”
        InstantiationUrl=“_layouts/expenseReportInitiationPage.aspx”
        ModificationUrl=“_layouts/expenseReportModificationPage.aspx”>
    <Categories/>
    <AssociationData>
    …
    </AssociationData>
    <MetaData>
    …
    </MetaData>
    </Workflow>
</Elements>
NoteNote

This sample has been edited for clarity.

Keep in mind that Windows SharePoint Services must use ASP.NET 2.0 to define input forms for workflow solutions. Microsoft Office InfoPath forms cannot be used for Windows SharePoint Services workflows. If you have an existing ASP.NET 2.0 application and want to take advantage of workflows in SharePoint, you can use Windows SharePoint Services workflows. On the other hand, Windows SharePoint Services workflow solutions can’t use Office client applications to interact with end users. That includes InfoPath forms. If you want seamless support for 2007 Microsoft Office system clients in custom OBA workflow solutions, Microsoft Office SharePoint Server 2007 is the better option.

Microsoft Office SharePoint Server 2007

Microsoft Office SharePoint Server 2007 provides a true enterprise portal platform and builds upon the Windows SharePoint Services 3.0 infrastructure. In the context of OBA workflow solutions, Office SharePoint Server 2007 provides the following capabilities:

Hosting of InfoPath forms thanks to the integration with InfoPath Forms Services

  • Integration with 2007 Microsoft Office system client applications such as Microsoft Office Outlook 2007, Microsoft Office Word 2007, Microsoft Office PowerPoint 2007, and Microsoft Office Excel 2007

  • Customization of out-of-the-box (OOB) workflows

  • Customization of workflows

Support for InfoPath Forms

Office SharePoint Server 2007 allows users to interact with workflows using InfoPath forms in the same way that users interact with ASP.NET 2.0 Web forms for Windows SharePoint Services workflows. Some developers prefer InfoPath forms over ASP.NET 2.0 forms for a couple of reasons:

  • InfoPath forms can be displayed by the 2007 Microsoft Office system clients. For example, you can host an InfoPath form in Word 2007, Excel 2007, PowerPoint 2007, or Outlook 2007.

  • InfoPath forms are easier to create. InfoPath 2007 provides a designer experience that helps you create forms faster and with less code. Also, InfoPath forms provide built-in validation and data proofing.

You can use a workflow definition schema file to define InfoPath forms for association, initiation, tasks, and modification that integrate with Office SharePoint Server 2007 workflows solutions. To define the custom forms you want to use in a workflow template definition, you must set the form URLs of each specific process (association, initiation, modification, edit task) to the appropriate ASP.NET 2.0 predefined page of an Office SharePoint Server 2007 instance as shown in Listing 7-2. Next, you add an element that specifies the URN for the custom InfoPath form you built for each type of process. Listing 7-2 shows a sample XML markup file for an expense reporting solution that uses InfoPath forms.

Listing 7-2. Example of XML markup file for an expense report solution using InfoPath forms

<?xml version=“1.0” encoding=“utf-8” ?>
<Elements xmlns=“http://schemas.microsoft.com/sharepoint/”>
    <Workflow
        Name=“ExpenseReportWorkflow”
        Description=“Use this workflow to track expense report status.”
        Id=“C6964BFF-BG8D-41ac-AC5E-B61EC111731C”
        CodeBesideClass=“OBAExpenseReport.Workflow1”
        CodeBesideAssembly=“OBAExpenseReport, Version=12.0.0.0, Culture=neutral,
            PublicKeyToken=71e3bce121e9429c”
        TaskListContentTypeId=“0x01080100C9C9515DE4E24001905074F980F93160”
        AssociationUrl=“_layouts/CstWrkflIP.aspx”
        InstantiationUrl=“_layouts/IniWrkflIP.aspx”
        ModificationUrl=“_layouts/ModWrkflIP.aspx”
        StatusUrl=“_layouts/WrkStat.aspx”>
    <Categories/>

    <!-- Tags to specify InfoPath forms for the workflow; delete 
    tags for forms that you do not have -->

      <MetaData>
        <Association_FormURN>
            urn:schemas-OBAExpenseReport-com:workflow:ReviewRouting-Assoc
        </Association_FormURN>
        <Instantiation_FormURN>
        urn:schemas-OBAExpenseReport-com:workflow:ReviewRouting-Init
        </Instantiation_FormURN>
        <Task0_FormURN>
             urn:schemas-OBAExpenseReport-com:workflow:ReviewRouting-Review
        </Task0_FormURN>
        <Task1_FormURN>
            urn:schemas-OBAExpenseReport-com:workflow:ReviewRouting-Review
        </Task1_FormURN>
        <AssociateOnActivation>false</AssociateOnActivation>
      </MetaData>
    </Workflow>
</Elements>

To design an InfoPath form for a workflow in Office SharePoint Server 2007, you use InfoPath 2007 and start designing a custom form the same way you would with any other InfoPath 2007 form. In general, to create InfoPath forms for workflow solutions, you start by adding controls on your form. Next, you data bind the controls so that the form can send and receive data to Office SharePoint Server 2007 and the workflow instance. Next, you add and customize a button that submits your form data to Office SharePoint Server 2007. Finally, you set the forms security level to Domain and publish the form. For more information about creating InfoPath forms, see Create an InfoPath form for office supply requisitions.

Figure 7-5 shows an InfoPath form used as an initiation form for an expense reporting workflow solution.

Figure 7-5. Sample InfoPath form for expense reporting workflow solution

InfoPath form for expense reporting workflow

Integration into 2007 Microsoft Office System Client Applications

One of the most powerful features offered by Office SharePoint Server 2007 is the ability to connect custom workflow solutions with Office Client applications. This allows end users to interact in a natural way with OBA workflow solutions. End users can interact with workflows directly from Word 2007, Excel 2007, PowerPoint 2007, and Outlook 2007. As mentioned in the previous section of this chapter, Office client applications can host InfoPath forms.

NoteNote

This option is available for users who installed InfoPath 2007.

For example, you can open, fill out, and submit InfoPath forms from Outlook 2007. InfoPath e-mail forms help streamline workflow processes that you use to collaborate and share data using well-known applications and, therefore, reduce the need for training. Figure 7-6 shows how you can open InfoPath forms in Outlook 2007.

Figure 7-6. Open InfoPath forms in Outlook 2007

Open InfoPath forms in Outlook 2007

Another powerful possibility offered by Office SharePoint Server 2007 is the ability for end users to initiate a workflow from Word 2007. You can open a Word 2007 document and create a running workflow instance by using the Start New Workflow option. This greatly simplifies the process of starting workflows involving document approval. Earlier in this chapter, we explored a state machine workflow document publishing scenario in which you work for an editorial company that publishes technical articles for software developers and you are asked to build an article publishing workflow application. In this scenario, contributors can use Word 2007 to initiate a document approval workflow right after they finish writing an article. Figure 7-7 shows how a contributor can initiate a document approval workflow instance from Word 2007.

Another integration possibility includes reporting tools that provide an aggregate analysis of workflow history. You may be interested in analyzing workflow processes to identify problems, bottlenecks, and the performance of your organization. Office SharePoint Server 2007 includes several predefined Excel 2007 reports that provide aggregate analysis of workflow history. Additionally, you can use Visio 2007, Access 2007, or custom monitoring solutions to analyze workflow history information stored in SharePoint lists.

Figure 7-7. Initiate a document approval workflow from Word 2007

Initiating document approval workflow in Word

Out-of-the-Box Workflows

Office SharePoint Server provides a set of out-of-the-box (OOB) workflow solutions. Information workers (IWs) can use these workflow templates with no developer intervention. However, you can customize predefined workflows based on your business needs. The predefined workflows templates in Office SharePoint Server 2007 include the following:

  • Approval   Provides business logic and predefined settings that help you route documents for approval. When the workflow is initiated, the end user defines a list of approvers.

  • Collect feedback   Provides business logic and predefined settings that help you route documents for review. This workflow is similar to the previous one. However, this workflow allows end users to provide feedback.

  • Collect signatures   Provides business logic and predefined settings that help you collect signatures for a document. This workflow works like the previous ones, but requires end users to provide a signature to complete a workflow. This workflow can be started only in Office client programs.

  • Disposition approval   Provides business logic and predefined settings that help users decide whether to retain or delete expired documents.

  • Three-state workflow   Provides business logic and predefined settings that help users track the status of a list item through three states. It can be used to manage business processes that require organizations to track a high volume of issues or items, such as customer support issues, sales leads, or project tasks.

  • Translation management workflow   Provides business logic and predefined settings that help manage document translation. This workflow allows users to assign tasks and track the status of translated documents.

To create OOB workflow solutions, you start by opening a document library, list, or content type. Next, you select Settings, Document Library Settings, and then Workflow. This opens an Add Workflow page that allows you to configure an OOB workflow. Figure 7-8 shows how you can create an OOB workflow in a preexisting workflow document library in Office SharePoint Server 2007.

Figure 7-8. Creating out-of-the-box workflow solutions in Office SharePoint Server 2007

Creating workflows in SharePoint Server

For more information, see Business Document Workflow.

Customization of Workflows

In many cases, you may want to create a custom workflow solution that is specific to your business needs. Office SharePoint Server 2007 and Windows SharePoint Services allow you to build custom workflow solutions using Office SharePoint Designer 2007 or Visual Studio 2008. The next section walks you through the process of building custom workflows using both tools.

You can create custom OBA workflow solutions for Windows SharePoint Services and for Office SharePoint Server 2007 using either Office SharePoint Designer 2007 or Visual Studio 2008. Both tools provide design templates that help you build workflow solutions. However, each authoring tool provides different capabilities.

Overview of Creating Custom Workflows in SharePoint Designer

Office SharePoint Designer 2007 provides a simple rules-based approach that enables you to create workflow solutions based on preexisting activities and to associate workflows directly to lists or document libraries. This authoring tool allows you to define workflows with no custom code. Office SharePoint Designer also simplifies the deployment process, since workflow markup, rules, and supporting files are stored in a specific document library. For those reasons, it is a tool commonly used by information workers and Web designers. You can use this authoring tool to build simple OBA workflow solutions that automate business processes in your enterprise such as document approval, document review, task management, and more. Figure 7-9 shows how you can create new workflows or open existing ones using Office SharePoint Designer as an authoring tool for workflows.

Figure 7-9. Creating workflows using Office SharePoint Designer 2007 as an authoring tool

Creating workflows using SharePoint Designer

Office SharePoint Designer 2007 provides a wizard-like designer that enables you to define workflow solutions that use a set of business rules and predefined rules, for example, sending notifications via e-mail. This greatly simplifies the process of building workflows. However, when you are making a technology decision, there are some considerations you should keep in mind if you plan to use Office SharePoint Designer 2007:

  • Workflow association   You can associate workflows to lists or document libraries, but you cannot associate workflows to content types. Once you associate a workflow, you cannot change which list or document library a workflow is attached to. Instead, you must create a new workflow and attach it to the list that you want.

  • Forms support   You can design custom ASP.NET 2.0 forms, but SharePoint Designer does not provide support for InfoPath forms. Something else to consider is that workflows authored from Office SharePoint Designer 2007 only support initiation and task completion forms. This is because workflows designed in SharePoint designer cannot be modified while running. Therefore, you cannot define modification forms. As explained earlier, you associate workflows directly to lists or document libraries, meaning the association process happens in design time. Therefore, you cannot define association forms.

  • Workflow authoring styles   You can create sequential workflows, but SharePoint Designer does not support state machine workflows.

Expense Report Scenario

Imagine that you work for Adventure Works Cycles, a sports store franchise that sells bicycles worldwide. This company has sales representatives that visit different countries to help new franchisees open new sports stores. You are asked to build a simple Expense Reporting OBA workflow solution. In this solution, sales representatives will start by filling out a simple expense report form that provides their name, the expense purpose, the expense total, and their direct manager’s name and e-mail address. When sales representatives submit the expense report, the workflow business rules need to verify that the expense total does not exceed $5,000. If the expense total exceeds $5,000, the workflow will submit an e-mail to the direct manager asking for approval. If the expense total is less than or equal to $5,000 the system will send an e-mail to the accounting department asking it to reimburse the sales representative with the expense total amount. Since this is a simple scenario that needs no coding, you decide to use Office SharePoint Designer 2007 to author this OBA workflow solution.

To create this workflow solution, first create a document library in Office SharePoint Server 2007. For this scenario, you name the document library Expense Reports. You must add an Expense Total column of type number to the document library. Once that is configured, use Office SharePoint Designer 2007 to associate the OBA workflow solution you are creating. Figure 7-10 shows the document library you use for the expense reporting solution.

Figure 7-10. Microsoft Office SharePoint Server 2007 document library for the expense reporting solution

Document library for expense reporting solution

To create the workflow solution, you open Office SharePoint Designer 2007. Next, you select the Open Site option from the File menu to select the SharePoint site where you want to create the workflow. Next, in the File menu, select New, and then click Workflow. This step will launch the Workflow Designer window, as shown in Figure 7-11.

Figure 7-11. The Workflow Designer window in Office SharePoint Server 2007

Workflow Designer window in SharePoint Server

The Workflow Designer window allows you to configure the name of the workflow. In this case, you will name the workflow ExpenseReport. Site visitors see this name when they view the Workflow pages and Workflow status in the Web browser. The Workflow Designer window enables you to select the SharePoint list or document that you want to use and associates it with the workflow. In this case, you will select the Simple Expense Reporting Demo document library that you created previously. Finally, the Workflow Designer window provides three check boxes that enable you to select whether you want to:

  • Allow the workflow to be started manually from an item.

  • Automatically start the workflow when a new item is created.

  • Automatically start the workflow whenever an item is changed.

For the expense reporting solution, you must select the first two checkboxes, as shown in Figure 7-11.

The Workflow Designer also provides an Initiation button that enables you to define the workflow parameters to collect data from participants who manually start workflows. In this case, you can define parameter values for the employee name, the expense purpose, the expense total, the manager’s name, and the manager’s e-mail address. Figure 7-12 shows the workflow initiation parameters for the expense reporting workflow scenario.

Figure 7-12. Workflow initiation parameters for the Expense reporting workflow scenario

Workflow initiation parameters

Once you are done defining the workflow initiation parameters, you can define the set of business rules for the workflow. The requirements of the OBA workflow solution define business rules that are specific for this scenario. We explained earlier that when sales representatives submit an expense report, the workflow business rules need to verify that the expense total does not exceed $5,000. If the expense total exceeds $5,000, the workflow submits an e-mail to the direct manager asking for approval. If the expense total is less than or equal to $5,000 the system sends an e-mail to the accounting department asking it to reimburse the sales representative with the expense total amount. The Workflow Designer window enables you to define business rules by using a set of predefined conditions that apply to your scenario. You can compare fields in a current list and perform actions based on satisfied conditions. For this solution, you need to define an if-then-else condition to compare if the expense total field is greater than $5,000. If this condition is satisfied, the manager will receive an e-mail notification, else the accounting department will receive an e-mail notification. Figure 7-13 shows the business rules definition process.

Figure 7-13. Business rules definition process

Business rules definition process

Once you click the Finish button in the Workflow Designer window, the workflow is saved and attached to the list you specified. Each time a sales representative submits an expense report, Office SharePoint Server 2007 launches a workflow instance and validates the business rules.

Workflow Project Templates in Visual Studio Tools for Office

At the beginning of this chapter, we discussed the challenges and opportunities that modern enterprises currently face when creating solutions that better integrate back-end systems and LOB information with commonly used information worker applications. Today, developers have in their hands a new set of developer tools and technologies that simplify the process of building solutions that connect back-end systems with Office client applications. As discussed in Chapter 4, you can define Software + Services (S+S) to build services that connect to LOB systems. The Office platform simplifies the integration between software services and software to simplify the consumption of these services.

In addition, Microsoft provides Visual Studio 2008 and Visual Studio Tools for the Microsoft Office system (3.0) as authoring tools that greatly simplify the development of elaborate OBA workflow solutions. Visual Studio Tools for Office 3.0 is a component that ships with Visual Studio 2008. Chapter 2 explains how you can build custom smart client solutions for your OBAs using Visual Studio Tools for Office. In addition, Visual Studio Tools for Office has an improved set of workflow project templates that support Rapid Application Development (RAD) of custom workflow SharePoint Solutions. Together, Visual Studio 2008 and Visual Studio Tools for Office provide tools that help you create custom workflow templates that manage the life cycle of documents and list items in a SharePoint Web site. Some of these tools include a graphic designer, a complete set of drag-and-drop activity controls, and the necessary assembly references you need to build a workflow solution. Visual Studio Tools for Office also includes the New Office SharePoint Workflow wizard, which greatly simplifies the configuration process and steps for creating workflow templates in Visual Studio. Figure 7-14 shows the different Visual Studio installed templates for the 2007 Office system. These templates include a SharePoint Sequential Workflow template and a SharePoint State Machine Workflow template.

Workflow solutions in Visual Studio 2008 allow a greater level of customization than workflow solutions authored in Office SharePoint Designer 2007. Not only can you use a predefined set of activities, but you can create new activities for use as workflow components. Additionally you can define forms for association, initiation, modification, and task editing using either ASP.NET 2.0 Web forms or InfoPath forms. Visual Studio 2008 provides support to design, code, and publish the forms to the server.

Figure 7-14. SharePoint Sequential Workflow and SharePoint State Machine Workflow templates in Visual Studio 2008

Workflow templates in Visual Studio 2008

As explained earlier, you can use Visual Studio 2008 to build workflow solutions for either Windows SharePoint Services or Office SharePoint Server 2007. Once compiled, workflow solutions are packaged as templates that can later be associated to different lists, document libraries, and content types. This provides another great advantage with respect to workflow solutions built with Office SharePoint Designer 2007. Another great advantage is that Visual Studio 2008 allows you to build workflow solutions and custom activities that you can reuse in different workflow solutions. You can, for example, create a custom activity that adds workflow steps as tasks in Outlook.

Finally, since you are using Visual Studio 2008, you are given all the advantages provided by Visual Studio as an authoring tool for developer solutions. Some of these advantages include the use of code-behind files, IntelliSense, debugging, use of the different workflow object models that enable workflow extensibility, and support for building custom classes and Web services that can bring LOB data.

Note   You can build workflow solutions with Visual Studio 2005 using the Visual Studio 2005 Designer for Windows Workflow Foundation add-in. This add-in is available as part of the Microsoft Windows Workflow Foundation Runtime Components and Visual Studio 2005 Extensions for Windows Workflow Foundation. However, Visual Studio 2008 reduces complexity and greatly speeds development of SharePoint workflow OBA solutions. For that reason, this book chapter focuses on showing the latest workflow enhancements added to Visual Studio 2008 and Visual Studio Tools for Office. For more information about the Visual Studio 2005 Designer for Windows Workflow Foundation, see Microsoft Windows Workflow Foundation Runtime Components Beta 2.2 and Visual Studio 2005 Extensions for Windows Workflow Foundation Beta 2.2. For more information about the Visual Studio 2005 extensions for the .NET Framework 3.0 (Windows Workflow Foundation), visit Visual Studio 2005 extensions for .NET Framework 3.0 (Windows Workflow Foundation).

Visual Studio 2008 offers a basic activity library (BAL) that provides a set of predefined activities you can use to define a workflow template. An activity is a step or task that performs an action in a workflow—for example, sending an e-mail, adding tasks to Outlook 2007, adding items to SharePoint lists, or connecting to an LOB database to retrieve or save information. While designing workflows, you can use the toolbox in Visual Studio 2008 to drag and drop activities to your workflow solution. Activities are built as classes, and therefore, have properties, events, and methods as any other class. You can use activities from either the Windows Workflow tab or the SharePoint Workflow tab. The Windows Workflow tab provides a set of activities provided by the Windows Workflow Foundation, while the SharePoint Workflow tab provides a set of activities that are specific to Windows SharePoint Services and Office SharePoint Server 2007. Some of these activities include OnWorkflowActivated, CreateTask, DeleteTask, SendEmail, and CompleteTask. Additionally, you can build your own custom activities by creating a class that implements the SequentialWorkflowActivity class if you need a sequential activity or the StateMachineWorkflowActivity if you need a state machine activity. Figure 7-15 shows the Windows Workflow 3.0 and the SharePoint Workflow toolbox tabs in Visual Studio 2008.

Figure 7-15. Windows Workflow 3.0 and the SharePoint Workflow toolbox tabs in Visual Studio 2008

Workflow toolbox tabs in Visual Studio 2008

For more information about creating custom activities, see Tutorial: Create a Custom Activity.

The next section of this chapter provides a high-level overview of, and guidance for, creating sequential workflows and state machine workflows using Visual Studio 2008 as an authoring tool.

Sequential Workflows

As we explained earlier, sequential workflows execute activities in a predefined pattern and represent a workflow as a procession of steps that must be executed in order until the last activity is completed. As shown in Figure 7-14, Visual Studio 2008 has a new SharePoint Sequential Workflow project template that provides a graphic workflow designer, a complete set of drag-and-drop activity controls, and the necessary assembly references you need to build a sequential workflow solution.

Previously, we talked about a scenario in which you have to build a vacation leave notification system for your company. When an employee saves a document, the direct manager receives an e-mail notification to let her know that she has to approve vacation time for an employee. If the manager approves the document, the system sends an e-mail to the employee. If the manager rejects the vacation request, the employee receives an e-mail with comments from the manager. In either case, the workflow reaches an end and terminates the execution. Because you want to add more customization and use debugging, you decide to use Visual Studio 2008.

To create this solution, you start by creating a simple Vacation and Time Off document library. You should add the following four columns to the document library, as shown in Figure 7-16.

  • Employee Name   Create this column as Single line of text.

  • Manager’s Name   Create this column as Single line of text.

  • Planned days off   Create this column as Number.

  • Notes   Create this column as Multiple line of text.

Figure 7-16. “Vacation and Time Off” document library

Vacation and Time Off document library

Workflow participants will use this document library to store vacation approval forms. Next, in Visual Studio 2008, you start by opening the New Project dialog box and selecting the SharePoint 2007 Sequential Workflow project located under the Office node. In the name box, you type OBAVacationApprovalDemo. This last step opens the New Office SharePoint Workflow wizard, as shown in Figure 7-17.

Figure 7-17. New Office SharePoint Workflow wizard

New SharePoint Workflow wizard

The next window prompts for a workflow name and a site for debugging the page. Click Next to accept the default settings. The next step requires that you select the document library, task list, and history list you want to use when debugging. In this case, you accept the default settings. The last step of the wizard requires you to define the conditions for how your workflow is started. Visual Studio 2008 allows you to automatically associate a workflow to a document library or list. Additionally, you can choose to handle the association step manually. In this case, you will associate the workflow with the Vacation and Time Off document library you created previously. Finally, the wizard asks for the conditions for how your workflow is started. In this case, you choose Manually by users and When an item is created.

Next, you open the Windows Workflow activities and the SharePoint Workflow activities in the toolbox to drag and drop activities to the Visual Studio 2008 design surface. Visual Studio 2008 enables you to create workflow diagrams just as you can create flowchart diagrams using Visio 2007. Figure 7-18 shows a completed sequential workflow diagram for the vacation leave notification system.

Figure 7-18. Sequential workflow diagram for the vacation leave notification system

Sequential workflow diagram for vacation leave

You can double-click each activity to customize code behind just as you can double-click buttons on Windows Forms solutions to add custom code. You can also define properties for each activity using the Properties window in Visual Studio 2008. Listing 7-3 shows the contents of the OBAVacationApprovalDemo sequential workflow class.

Listing 7-3. OBAVacationApplicationDemo sequential workflow class

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;
using Microsoft.Office.Workflow.Utility;

namespace OBAVacationApprovalDemo {
    public sealed partial class Workflow1 : SequentialWorkflowActivity {

        private bool _taskCompleted = false;

        public Workflow1() {
            InitializeComponent();
        }

        public Guid workflowId = default(System.Guid);
        public SPWorkflowActivationProperties workflowProperties = new
        SPWorkflowActivationProperties();
        public static DependencyProperty approveTaskIdProperty = 
          DependencyProperty.Register(“approveTaskId”, typeof(System.Guid),
          typeof(OBAVacationApprovalDemo.Workflow1));
           [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
           [BrowsableAttribute(true)]
           [CategoryAttribute(“Misc”)]
           public Guid approveTaskId {
            get {
                return
       ((System.Guid)(base.GetValue(OBAVacationApprovalDemo.Workflow1.approveTaskIdProperty)));
            }
            set {
                base.SetValue(OBAVacationApprovalDemo.Workflow1.approveTaskIdProperty, value);
            }
        }

        public static DependencyProperty approveTaskPropertiesProperty = 
        DependencyProperty.Register(“approveTaskProperties”,
        typeof(Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties),
        typeof(OBAVacationApprovalDemo.Workflow1));
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [CategoryAttribute(“Misc”)]
        public SPWorkflowTaskProperties approveTaskProperties {
            get {
                return
      ((Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties)
      (base.GetValue(OBAVacationApprovalDemo.Workflow1.approveTaskPropertiesProperty)));
            }
            set {

        base.SetValue(OBAVacationApprovalDemo.Workflow1.approveTaskPropertiesProperty, value);
            }
        }

        private void approveTaskCreation(object sender, EventArgs e) {
            try {
                approveTaskId = Guid.NewGuid();
                approveTaskProperties = new
                    Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
                approveTaskProperties.AssignedTo =
                    System.Threading.Thread.CurrentPrincipal.Identity.Name;
                approveTaskProperties.Title = “Vacation and Time off Workflow Task”;
                approveTaskProperties.Description = String.Format(
                 “This is a vacation and time off request ” +
                 “submitted by {0} [Employee Name] to {1} [Manager’s Name]. ” +
                 “The employee is planning to take {2} days off.”,
                        CustomFieldValue(“Employee Name”),
                        CustomFieldValue(“Manager’s Name”),
                        CustomFieldValue(“Planned days off”));
                    approveTaskProperties.PercentComplete = (float)0.0;
                    approveTaskProperties.StartDate = DateTime.Now;
                    approveTaskProperties.DueDate = DateTime.Now.AddDays(10);
                    approveTaskProperties.EmailBody = “Your vacation and time off request
                        was approved by your manager.”;
                    approveTaskProperties.SendEmailNotification = true;
                }
                catch (Exception ex) {
                    throw (new Exception(“Unable to initialize workflow task.”, ex));
                }
            }
            private string CustomFieldValue(string fieldName) {
                object item = this.workflowProperties.Item[fieldName];
                string s = this.workflowProperties.Item.Fields[fieldName]
                        .GetFieldValueAsText(item);
                if (s != null) {
                    return s;
                }
                else {
                    return String.Empty;
                }
            }
                private void approveTaskNotCompleted(object sender, 
                  ConditionalEventArgs e){ e.Result = !_taskCompleted;
            }

                public static DependencyProperty afterApproveTaskPropertyChangeProperty =
                DependencyProperty.Register(“afterApproveTaskPropertyChange”,
                typeof(Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties),
                typeof(OBAVacationApprovalDemo.Workflow1));
             [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
             [BrowsableAttribute(true)]
             [CategoryAttribute(“Misc”)]
            public SPWorkflowTaskProperties afterApproveTaskPropertyChange {
                get {
                    return
  ((Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties)
  (base.GetValue(OBAVacationApprovalDemo.Workflow1.afterApproveTaskPropertyChangeProperty)));
                }
                set
{base.SetValue(OBAVacationApprovalDemo.Workflow1.afterApproveTaskPropertyChangeProperty, value);
                }
            }

            private void onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e) {
                if (afterApproveTaskPropertyChange.PercentComplete == 1.0) {
                    _taskCompleted = true;
                }
            }
        }
}

Once you are done writing code for the vacation leave notification system, you can test the solution by using the Visual Studio debugger. When you debug the solution, Visual Studio deploys the solution to a SharePoint site and it adds the workflow template to a library or list. You can start an instance of the workflow template to test the solution while using standard debugging tools that help you debug your code as you would do with any other Visual Studio solution.

State Machine Workflows

As we explained earlier, state machine workflows respond to external events as they occur and represent a group of states, transitions, and events, which trigger transitions between these states. As shown in Figure 7-14, Visual Studio 2008 also provides a new SharePoint State Machine Workflow project template that provides a graphic workflow designer, a complete set of drag-and-drop activity controls, and the assembly references you need to build a state machine workflow solution.

To create state machine in Visual Studio 2008, start by creating a document library or list that you want to use for a custom solution. Next, in Visual Studio 2008, open the New Project dialog box and select the SharePoint 2007 State Machine Workflow project located under the Office node. In the name box, type the name of your solution. This last step opens the New Office SharePoint Workflow wizard, as shown in Figure 7-16.

The design, development, and debugging of state machine workflows is almost identical to that of sequential workflows. As mentioned before, the only difference is that state machine workflows are event-driven, and therefore, you can create event-driven workflow solutions. Figure 7-19 shows a state machine workflow diagram for the article publishing workflow application scenario we discussed earlier.

Figure 7-19. State machine workflow for document approval

State machine workflow for document approval

Deployment

Visual Studio 2008 simplifies the deployment process by providing a deployment wizard that helps you create a workflow template package that you can use to deploy in different servers. Additionally, when you debug a workflow solution, Visual Studio 2008 deploys the workflow template and required configuration files to the SharePoint development site you used to create your solution. However, if you want to deploy the workflow template to a different server, you must perform additional deployment and configuration steps.

You can create a feature package to encapsulate a workflow solution and deploy it to different servers. A feature package is a CAB file with a .wsp file-name extension that contains the following files:

  • Feature.xml   XML-based file that contains a manifest listing the contents of a workflow solution. It provides high-level information, including the title, description, version, and scope of the workflow. Listing 7-4 shows a sample feature.xml file for the OBAVacationApprovalDemo solution.

    Listing 7-4. Sample feature.xml file for the OBAVacationApprovalDemo solution class

    <?xml version=“1.0” encoding=“utf-8” ?>
    <Feature  Id=“cf5c48e7-3428-4982-a039-898cbff616c2”
        Title=“OBAVacationApprovalDemo feature”
        Description=“Vacation and Time Off Approval Feature”
        Version=“12.0.0.0”
        Scope=“Site”
        ReceiverAssembly=“Microsoft.Office.Workflow.Feature, Version=12.0.0.0,
        Culture=neutral, PublicKeyToken=71e9bce111e9429c”
        ReceiverClass=“Microsoft.Office.Workflow.Feature.WorkflowFeatureReceiver”
        xmlns=“http://schemas.microsoft.com/sharepoint/”>
    <ElementManifests>
        <ElementManifest Location=“workflow.xml” />
    </ElementManifests>
        <Properties>
        <Property Key=“GloballyAvailable” Value=“true” />
    
        <!-- Value for RegisterForms key indicates the path to the forms relative to feature file location -->
        <!-- if you don’t have forms, use *.xsn -->
     
       <Property Key=“RegisterForms” Value=“*.xsn” />
        </Properties>
    </Feature>
    
  • Workflow.xml   XML-based file that specifies details about the workflow assembly, metadata, and the custom forms (InfoPath forms or ASP.NET Web forms) needed for the workflow. Listing 7-5 shows a sample workflow.xml file for the OBAVacationApprovalDemo solution.

    Listing 7-5. Sample workflow.xml file for the OBAVacationApprovalDemo solution

    <?xml version=“1.0” encoding=“utf-8” ?>
    <Elements xmlns=“http://schemas.microsoft.com/sharepoint/”>
      <Workflow
        Name=“OBAVacationApprovalDemo”
        Description=“Vacation and Time Off Approval Workflow”
        Id=“36cc9d57-d857-42ea-ad90-e461d58203ac”
        CodeBesideClass=“OBAVacationApprovalDemo.Workflow1”
        CodeBesideAssembly=“OBAVacationApprovalDemo, Version=1.0.0.0, Culture=neutral,
        PublicKeyToken=6f9ec6d2f579b3c8”>
        <Categories/>
        <MetaData>
            <StatusPageUrl>_layouts/WrkStat.aspx</StatusPageUrl>
        </MetaData>
      </Workflow>
    </Elements>
    
    
  • Compiled assembly   The feature package installs a compiled workflow assembly into the global assembly cache (GAC). We recommend that you sign the assembly using a strong key before you deploy the workflow solution to the server.

  • Custom forms   You must include custom forms needed for the workflow. If the workflow solution uses ASP.NET Web forms, the feature package must provide instructions to deploy the forms to the Layouts folder of the server that will run the workflow solution. On the other hand, if the workflow solution uses InfoPath forms, the feature package must provide instructions to deploy the forms to the Features folder of the server that will run the workflow solution shown in Listing 7-7.

    NoteNote

    You can install InfoPath forms automatically to the server if you define the forms using the element of the feature.xml file.

Building a Feature Package

To build a feature package, you start by defining the solution files and the destination directory of all workflow solutions that must be deployed to the front-end Web server. The previous configuration and installation instructions must be defined using a manifest.xml file and a CAB file.

  • Manifest.xml   XML-based file used as a header file that defines the files that must be deployed to a front-end Web server. Listing 7-6 shows a sample manifest.xml file used for the OBAVacationApprovalDemo solution.

    Listing 7-6. Sample manifest.xml file used for the OBAVacationApprovalDemo solution

    <?xml version=“1.0” encoding=“utf-8”?>
    <Solution SolutionId=“36cc9d57-d857-42ea-ad90-e461d58203ac”
                    xmlns=“http://schemas.microsoft.com/sharepoint/”>
        <FeatureManifests>
            <FeatureManifest Location=“OBAVacationApprovalDemo\feature.xml”/>
        </FeatureManifests>
        <Assemblies>
            <Assembly DeploymentTarget=“GlobalAssemblyCache”
                    Location=“OBAVacationApprovalDemo.dll”/>
        </Assemblies>
    </Solution>
    
  • Solution.ddf file   CAB file that specifies which files to include in the output CAB file. Listing 7-7 shows a sample solution.ddf file used for the OBAVacationApprovalDemo solution.

    Listing 7-7. Sample solution.ddf file used for the OBAVacationApprovalDemo solution

    .OPTION EXPLICIT
    .Set CabinetNameTemplate=OBAVacationApprovalDemo.wsp
    .Set DiskDirectoryTemplate=CDROM
    .Set CompressionType=MSZIP
    .Set UniqueFiles=“ON”
    .Set Cabinet=on
    .Set DiskDirectory1=OBAVacationApprovalDemo
    
    Solution\manifest.xml manifest.xml
    
    .Set DestinationDir=OBAVacationApprovalDemo
    OBAVacationApprovalDemo\Feature.xml
    OBAVacationApprovalDemo\workflow.xml
    OBAVacationApprovalDemo\bin\debug\OBAVacationApprovalDemo.dll
    
    

Once you create the previous feature package files, you can create a .wsp package file using the makecab.exe command-line utility, as shown in Listing 7-8.

Listing 7-8. Create a .wsp package file using the makecab.exe command-line utility

makecab /f Solution\solution.ddf

Once you create the feature package, you use the stsadm.exe command-line tool to install and activate the workflow solution. Listing 7-9 shows how to install a feature using the stsadm command-line tool.

Listing 7-9. Use the stsadm.exe command-line tool to install the workflow solution

stsadm –o installfeature –filename <path of the Feature.xml file relative to the
12\TEMPLATE\FEATURES folder >

Listing 7-10 shows how to activate a feature using the stsadm command-line tool.

Listing 7-10. Use the stsadm.exe command-line tool to activate the workflow solution

stsadm –o activatefeature –name < folder in FEATURES directory containing the Feature
.xml file > -url http://Server/Site/Subsite

It is recommended that a server administrator deploys the workflow solution to a front-end Web server. Once the workflow solution is installed and activated, a site administrator must associate workflows with lists, document libraries, or content types.

So far, we’ve explored sample scenarios that have well-known business rules. For example, in the expense report scenario, the business rules are always the same. This workflow solution defines the direct manager as a single approver, and the content of the notifications is predefined as well. Depending on the expense total value, the workflow solution will either send a notification to the manager or to the accounting department. However, there are many real-world applications that have complex business rules. Routing for approval can depend on many business variables, and notifications can change depending on some other variables. Imagine that in the same expense reporting solution, you have to route an expense report to up to ten different managers, depending on the expense purpose, the expense total, and the date of submission. Additionally, depending on the expense purpose, the content of the notifications sent by the workflow will have some slight differences. This means that there may be multiple workflow solutions with different routing levels and notifications. In all previous solutions discussed in this chapter, the approvers and notifications of the solutions are predefined, meaning that each workflow instance will always follow the same business logic and execute the same predefined activities. However, for OBA workflow solutions in which you need more flexibility, you must build a separate component that encapsulates complex business rules. Depending on the complexity of the business rules of your solution, you may either create a database that stores and validates all these business rules, create custom business layer classes or Web services, or use Excel 2007 as a business rule storage for decision sets.

Excel 2007 simplifies the rules capture and decision process for notifications and approvals. Implementing decision tables using Excel 2007 represents low costs for companies that already invested in 2007 Microsoft Office systems licenses. To add to the benefits, Excel 2007 provides a comfortable environment for rules administrators and requires minimal investment in training. Figure 7-20 shows routing rules in Excel 2007 and Figure 7-21 shows notification rules in Excel 2007.

Figure 7-20. Routing rules in Excel 2007

Routing rules in Excel 2007
Figure 7-21. Notification rules in Excel 2007

Notification rules in Excel 2007

You can use Excel 2007 to store decision tables that capture approval, routing, and notification values. Thanks to the Open XML Formats, you can easily extract routing and approval domain information from Excel 2007 spreadsheets. Depending on your business needs, you can create a sequential or state machine workflow template using Visual Studio 2008. As part of your workflow template solution, you can use the Open XML Object Model API to retrieve business rules information from the decision tables stored in Excel 2007 spreadsheets.

Now that you have learned about the workflow capabilities offered by the 2007 Microsoft Office system, you can start thinking about different custom OBA workflow solutions that you can create for your company. You can use different Microsoft products and technologies to leverage your current technology investments and greatly simplify your business processes. Creating workflow solutions can be as simple as running configuration wizards using Office SharePoint Designer 2007, and as flexible as you can imagine if you use Visual Studio 2008 as an authoring wizard. What’s most interesting is that you can enable workflow participants to use Office client applications, since they are already comfortable working with these programs. The possibilities are endless and rely completely on your business needs. Enjoy the process of building custom OBA workflow solutions. The results can be gratifying.

The 2007 Microsoft Office system is a true developer platform that helps connect LOB information and Office client applications. Workflow solutions integrate many different Microsoft products and technologies, and we want to provide as many as possible. The space is limited, but here is a list of key developer resources that can help you with a deep dive into workflow capabilities offered by different Microsoft products and technologies.

Windows Workflow Foundation (WF)

Windows SharePoint Services

Office SharePoint Server 2007

InfoPath 2007 and Outlook 2007

Office SharePoint Designer 2007

Visual Studio 2008

Workflow Deployment

Open XML File Formats

Office Development

Show:
© 2014 Microsoft