Office 2010 Workflow:

Size: px
Start display at page:

Download "Office 2010 Workflow:"

Transcription

1 Office 2010 Workflow: Developing Collaborative Solutions MARK J. COLLINS

2 Office 2010 Workflow: Developing Collaborative Solutions Copyright 2010 by Mark J. Collins All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): ISBN-13 (electronic): Printed and bound in the United States of America Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Jonathan Hassell Technical Reviewers: Robert Garrett and Michael Mayberry Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Anne Collett Copy Editor: Kim Wimpsett Compositor: Kimberly Burton Indexer: Potomac Indexing, LLC Artist: April Milne Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY Phone SPRINGER, fax (201) , orders-ny@springer-sbm.com, or visit For information on translations, please rights@apress.com, or visit Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. ebook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales ebook Licensing web page at The information in this book is distributed on an as is basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at You will need to answer questions pertaining to this book in order to successfully download the code. ii

3 Contents at a Glance Preface... xix About the Author... xxi About the Technical Reviewers... xxii Acknowledgements... xxiii Introduction... xxiv PART 1: Introduction...1 Chapter 1: Overview of Microsoft Office...3 Chapter 2: Setting Up a Development Environment...11 Chapter 3: SharePoint Primer...45 PART 2: Using Workflows...57 Chapter 4: Three-state Workflow...59 Chapter 5: Office Applications as Workflow Participants...77 Chapter 6: Creating Workflows with SharePoint Designer...97 Chapter 7: Creating Reusable and Site Workflows PART 3: Workflows in Visual Studio Chapter 8: Creating a Simple Site Workflow Chapter 9: Exploring the SharePoint Object Model Chapter 10: Custom Workflow Forms Chapter 11: Handling Events Chapter 12: LINQ to SharePoint Chapter 13: Using State Machine Workflows PART 4: Miscellaneous Topics Chapter 14: Using a ConditionedActivityGroup Chapter 15: Importing Reusable Workflows Chapter 16: Creating Custom Actions Chapter 17: Pluggable Workflow Services PART 5: Business Connectivity Services (BCS) Chapter 18: Creating External Content Types Chapter 19: Implementing a.net Assembly Connector Chapter 20: Using External Lists in Outlook Index iv

4 Contents Preface... xix About the Author... xxi About the Technical Reviewers... xxii Acknowledgements... xxiii Introduction... xxiv PART 1: Introduction...1 Chapter 1: Overview of Microsoft Office...3 End-User Perspective...3 Office Overview... 3 Workflows in SharePoint... 4 Workflow Overview...5 Code-less Workflows... 6 Visual Studio Workflows... 6 Business Connectivity Services...6 Technology Overview...7 Software Products... 7 Client-Server Topology... 9 Summary...10 Chapter 2: Setting Up a Development Environment...11 Single-Computer Installation...11 Initial Setup SQL Server v

5 Active Directory Installing SharePoint on a Server OS...12 Installing the Prerequisites Installing SharePoint Server Running the SharePoint Products Configuration Wizard Using the Central Administration Web Application Installing SharePoint on a Desktop...26 Installing the Prerequisites Enabling Windows Features Installing SharePoint Server...32 Installing Hotfix KB Running the Configuration Wizard Initial Site Configuration Installing Other Applications...39 Installing Visual Studio Office Client Applications SharePoint Designer Installing Office Installing Visio Configuring Providing an System Configuring SMTP Summary...43 Chapter 3: SharePoint Primer...45 Columns...45 Text Columns Date & Time Columns Person or Group Columns vi

6 Choice Columns Lookup Columns Calculated Columns Site Columns Collection Content Types...51 Lists and Libraries...51 Supporting Content Types Views Subsites...53 Templates...54 Site Templates List Templates Summary...56 PART 2: Using Workflows...57 Chapter 4: Three-state Workflow...59 Creating a New Site...59 Creating a New List Understanding the Workflow Process Defining the List Columns Associating the Workflow...65 Defining the First Transition Defining the Second Transition Using the Work Request Workflow...70 Workflow Tasks...74 Summary...76 Chapter 5: Office Applications as Workflow Participants...77 Creating a SharePoint Site...77 vii

7 Creating a Document Library Associating a Workflow Using the Document Workflow...82 Submitting a New Design Document Enabling Office Receiving Workflow Notifications Receiving a Task Notification Using Office Shortcuts Integrating the Task List...89 Executing the Workflow Again Displaying the Task in Outlook More About Tasks...92 Working with Multiple Task List Deleting Tasks Summary...95 Chapter 6: Creating Workflows with SharePoint Designer...97 Creating the Site...97 Creating a Custom List Defining the List Columns Using Visio to Define a Workflow Designing a Workflow in Visio Exporting a Visio Workflow Importing a Visio Workflow Entering the Workflow Definition Specifying a Condition Creating a Calendar Entry Adding Workflow Details Configuring the Workflow viii

8 Executing the Workflow Exporting to Visio Summary Chapter 7: Creating Reusable and Site Workflows Reusable Workflows Creating a New Site Creating a Reusable Workflow Workflow Editor Overview Initiation Form Parameters Entering the Workflow Definition Checking the Review Outcome Adding a Second Step Publishing the Workflow Associating the Workflow Testing the Workflow Site Workflows Initiation Form Parameters Designing the Workflow Testing the Workflow Summary PART 3: Workflows in Visual Studio Chapter 8: Creating a Simple Site Workflow Using Visual Studio Creating a SharePoint Project Running as Administrator Configuring the SharePoint Project SharePoint Support in Visual Studio Designing a SharePoint Workflow ix

9 Logging to the History List Creating a New Task Defining the Activity s Properties Entering Code in the Code-Beside Class Deploying the Workflow Running the Workflow Visual Studio Cleanup Resolving Retract Issues SharePoint Deployment Configuration Selecting the Active Configuration Summary Chapter 9: Exploring the SharePoint Object Model Creating a SharePoint Project in Visual Studio Adding a Workflow SharePoint Customization Wizard Writing SharePoint Details to the History List Creating the Workflow Design Accessing the Object Model Testing the Workflow Scanning the Tasks List Adding an Activity to Check the Tasks List Implementing Check Tasks Logic Testing the Workflow More About Content Types Summary Chapter 10: Custom Workflow Forms Creating a Sequential Workflow Adding an Initiation Form x

10 Customizing the Initiation Form Getting the Initiation Data in the Workflow Implementing the Workflow Replicator Activity Setting Up the Replicator Activity CreateTask Activity Testing the Workflow Content Types Creating a Content Type Content Type Inheritance Adding Field Definitions Adding the Field References Using the New Content Type Testing the Workflow Creating Custom Task Forms with InfoPath Connecting to SharePoint Modifying the Form Layout Defining Rules Publishing the Form Testing the Custom Form Summary Chapter 11: Handling Events Modifying the Calendar List Adding the MenuUrl Column Adding the Attendees Column Creating a New Event Designing the Workflow Creating the Workflow Project xi

11 Managing the Tasks Getting the Workflow Parameters Using the Replicator Activity Task Activities Adding a Final Step Testing the Workflow Summary Chapter 12: LINQ to SharePoint Setting Up the Project Copying the Chapter 11 Project Configuring the Debugging Site Testing the Workflow SPMetal Running SPMetal Default Generation Rules Configuring SPMetal Using LINQ to SharePoint Adding a Collection Step Writing a LINQ Query Collecting the Orders Testing the Workflow Summary Chapter 13: Using State Machine Workflows Creating the Sample Project Creating the BugList Creating Tasks List Content Types Feature Summary Deploying the BugList Project xii

12 Creating a List Instance Creating the BugList Workflow Creating the Workflow Project State Machine Overview Designing the Workflow Adding the States Adding State Initialization Adding Event Logic Gathering Task Details Specifying the Event Activities Handling the Work Task Implementing the Assign State Initialization Sequence Implementing the Active State Initialization Sequence Adding Additional State Processing Configuring CreateTaskWithContentType Setting the BugStatus Implementing the Event Handlers Assigned State Active State Working as Designed State Waiting State Adding an Association Form Testing the Workflow Summary PART 4: Miscellaneous Topics Chapter 14: Using a ConditionedActivityGroup Setting Up the Project Creating a Part4 Site xiii

13 Creating the Visual Studio Project Designing the Workflow Creating the Task ConditionedActivityGroup Activity Designing the First Child Activity Designing the Second Child Activity Using the DelayActivity Testing the Workflow Summary Chapter 15: Importing Reusable Workflows Creating a Workflow in the SharePoint Designer Designing the Workflow Testing the Workflow Exporting the Workflow Site Assets Importing the Workflow Modifying the Workflow Associating the Workflow Testing the Workflow Summary Chapter 16: Creating Custom Actions Setting Up the SharePoint Project Designing a Custom Activity Adding the SharePoint References Implementing the Custom Activity Dependency Properties Creating the Event Generating a Strong Name xiv

14 Finding the Public Key Token Defining the Action Adding a Mapped Folder Adding an Actions File Rule Designer Deploying the ActivityLibrary Adding the Assembly Defining a Feature Implementing an Event Receiver Testing the Custom Action Creating a Site Workflow Using the Create Event Action Testing the Workflow Summary Chapter 17: Pluggable Workflow Services Creating the Workflow Project Creating a Local Service Defining the Interface Implementing the Service Generating a Strong Name Deploying the FileService Assembly Implementing an Event Receiver Implementing the Workflow Implementing CallExternalMethodActivity Implementing HandleExternalEventActivity Sending an Testing the Workflow Summary xv

15 PART 5: Business Connectivity Services (BCS) Chapter 18: Creating External Content Types Creating a Read-Only List Creating an External Content Type Creating a Database Connection Creating a Read Item Operation Creating a Read List Operation Setting Permissions Creating the Employees External List Creating an Updatable List Creating the External Content Type Creating the Sales Person List Defining an Association Creating the Territory External Content Type Adding the Association Configuring the Association Testing the Changes Summary Chapter 19: Implementing a.net Assembly Connector Creating the Business Data Connectivity Project Using the BDC Explorer Updating the Method Details Using the BDC Explorer The BDC Model File Implementing the CRUD Operations Defining the Data Class Using LINQ to SQL Configuring the Database Connection xvi

16 Implementing the Operations Testing the ProductDetail External Content Type Creating a Updatable External Content Type Adding a New Entity Defining the Data Class Defining the ReadItem Method Defining the Review Fields Creating the Remaining Operations Removing Fields Implementing the CRUD Operations Testing the Review External Content Type Creating an Association Defining Associations Implementing the Association Methods Testing the Changes Summary Chapter 20: Using External Lists in Outlook Linking the External Content Type Mapping to Office Connecting to Outlook Synchronizing Data Changing the Limit Filter Applying the Changes Linking the Territories List Modifying the Territory External Content Type Mapping to Office Connecting to Outlook Adding a Territory xvii

17 Summary Index xviii

18 P A R T 1 Introduction Implementing a Office workflow solution can be a bit daunting at first glance. Before I get into all the technical details, I think it would be useful to set the stage in order to establish a common perspective. In Chapter 1, I ll present the big picture to help you see how all the pieces fit together and describe the areas that I will focus on in this book. Chapter 2 will show you how to set up a development environment so as we start to build real solutions, you be able to deploy and test them. Chapter 3 provides a brief primer on SharePoint development for those who are new to SharePoint. It explains the basic concepts of columns, content types, and lists. The remainder of this book will present sample projects that demonstrate how to build workflow solutions in Office I ll start with some fairly simple projects and gradually build more complex solutions. Along the way, I ll explain key concepts that will help you master this technology.

19 C H A P T E R 1 Overview of Microsoft Office In this book, I ll be discussing a lot of software products such Microsoft Office, SharePoint, Workflow Foundation, SQL Server, and Visual Studio. In this Chapter, I ll explain how these work together and how (and when) each of these is used. End-User Perspective But first, let s take a step back and view all this technology from the perspective of the people who will benefit the most the end users. Office Overview The Microsoft Office suite of products allows you to author all types of documents including spreadsheets, diagrams, presentations, calendars, and so on. SharePoint then provides a repository for storing, sharing, and maintaining those documents. Through a flexible security model, SharePoint controls what each person can see and what they are allowed to change (and who is notified when a change is made). The concept of lists used in SharePoint is a slight departure from that model. Although these can be thought of as a list of documents, the things we generally keep lists of such as requests, tasks, and bugs can t really be called documents. Discussions are a special type of list that allows for items to be associated with other items in the list. So, a SharePoint site is a collection of Documents, Lists, and Discussions. Figure 1-1 shows the navigation window of the default SharePoint portal, which emphasizes this point. Figure 1-1. Default SharePoint navigation window 3

20 CHAPTER 1 OVERVIEW OF MICROSOFT OFFICE The documents are created through one of the familiar Office products such as Word. The items in a list, however, are usually created though a SharePoint form. Figure 1-2 shows the standard Task form that comes with SharePoint 2010 out of the box. Figure 1-2. The standard Task form This is all really cool and way better than a room full of filing cabinets. But this is still fairly static. Workflows in SharePoint This is where workflows come in. Workflows define the processes that are applied to each of these documents, lists, or discussions. For example, suppose you had a list of service requests. Someone would use a form to initiate a request, and someone else will, ideally, respond to that request. A workflow-driven list could add the following: 4