SharePoint Workflow DevelopmentUsing Visual StudioBrian LaSitisFebruary 27, 2008
TopicsWhy use Visual Studio vs. SP Designer?Advantages & DisadvantagesWindows WF OverviewGeneral Concepts & Usage ScenariosWorkflow TypesActivity OverviewSharePoint WF ExtensionsCustom Workflow SolutionsDemoCustom SP Designer ActionsDemo
SharePoint Designer - WorkflowAdvantagesDisadvantagesTargets the Information WorkerAllows business users to apply simple business logic within a document library or listUses a rules-based approach, similar to the Rules Wizard in OutlookCan be deployed without installing custom code to a server
Default capabilities limited to the actions available out of boxLimited wide-deployment options since each workflow is inherently tied to a specific list/document libraryDoes not support state-machine workflowsWorkflows cannot be modified while they are executing
Visual Studio / Windows WFAdvantagesDisadvantagesGraphical, flow-chart like development tools.Builds upon WF foundation, and adds SharePoint-specific activities.Supports custom association, initiation, modification, and task forms.Allows deployment through use of SharePoint features.Requires significant knowledge of the .NET development and the WF framework.Requires custom code to be deployed to the SharePoint server.Requires the developer to fully understand the underlying business logic of the workflow process.
SharePoint Features OverviewModular framework for deploying functionality within a specific scope within SharePoint:FarmWeb ApplicationSite CollectionWeb SiteStored within 12\TEMPLATE\FEATURES.Must be installed and activated to be used within their configured scope.Can be stapled to existing site collections, including those provided out-of-the-box.
What is Windows WF?A pillar within the .NET Framework 3.0 that provides the programming model, engine, and toolset for creating workflows in WindowsNot product specific; leveraged by many products.In its most basic form, WF is a multithreaded execution engine that can be leveraged by any type of .NET applicationGraphical development tools are directly integrated with Visual Studio 2005, through the Windows WF Designer.
WF Usage ScenariosWindows WF can be leveraged for any of the following:Workflow within LOB applicationsWindows Forms / ASP.NET UI Page FlowDocument-centric workflowHuman workflowComposite workflow for SOABusiness rule-driven workflowWorkflow for systems management
What products use Windows WF?Windows SharePoint Services 3.0Microsoft Office SharePoint Server 2007Microsoft BizTalk Server 2006 R2Microsoft Dynamics CRM 4.0Microsoft Identity Integration Server
A WF Workflow DefinitionCan be one of three types: sequential, state-machine, or rules-based.Composed of a set of activities, that are interconnected to form a business process.
SequentialState-MachineRules-BasedIdeal for business processesIdeal for processes with external interactionIdeal for complex decision scenariosTypically execute autonomously without external interactionTypically are reliant upon outside control to complete executionTypically use large, chained rule-trees to drive executionExecution controlled by the workflow itselfEvents control the workflow executionRules & policies control workflow executionRoot Activity: SequentialWorkflowRoot Activity: StateMachineWorkflowEither state-machine or sequential can be used.
Common WF Activities
Activity NameDescriptionSequence ActivityComposite activity that executes the set of activities within it in a sequential fashion.Code ActivityExecutes a snippet of .NET code.IfElse ActivityImplements If-Then-Else conditional logic within a workflow.While ActivityImplements looping logic within a workflow.Parallel ActivityComposite activity that executes two or more Sequence activities in a cooperative multithreaded manner.CallExternalMethod ActivityInvokes an external (.NET) method on an object, as defined in an interface bound to the activity.
The Workflow RuntimeThe Workflow Runtime is responsible for coordinating the following events:Starting workflow instancesInvoking workflow eventsTracks and uses pluggable services for providing functionality such as transactions, persistence, and tracking.Only one Workflow Runtime can exist within the application executing the workflow.Windows Forms, Console, ASP.NET applicationsWindows ServicesSharePoint
SharePoint Workflows in WFSharePoint extends the WF foundational framework by adding new workflow activities.Visual Studio add-ins are installed as part of the SharePoint 2007 SDK; supported by VS 2005 & 2008.It is advisable to perform the development of SharePoint WF workflows on an actual server running SharePoint.Results in simplified development and deployment since assembly references and post-build deployment steps are automated using the default project templates.The development of custom workflow actions in Visual Studio that are callable from SP Designer workflows is also possible.
Custom Workflow FormsSharePoint WF-based workflows can be configured to use a custom form for association, instantiation, and modification, as well as custom task forms.These can be implemented as ASPX forms or as InfoPath web-enabled forms (MOSS only)
Form TypeDescriptionAssociationUsed to capture information when a workflow is associated with a list or document library.InitiationUsed to capture information when a workflow is manually started for an item by a user.Task CompletionUsed to capture custom information when a workflow participant completes a task.ModificationUsed to capture changes for processing workflows, if they are modified externally.
SharePoint WF Activities
Activity NameDescriptionOnWorkflowActivated ActivityStarting activity for all SharePoint WF workflows; can accept inputs from Association & Initiation forms.CreateTask ActivityCreates a new task for a given user in the workflow.OnTaskChanged ActivityCaptures changes to a task that affect workflow processing.SendEmail ActivitySends email to a person or group of people.LogToHistoryList ActivityAllows entries to be written to a workflows History list, for tracking purposes.OnWorkflowModified ActivityAccepts inputs from the Modification form to change a workflows behavior.
SharePoint WF Development TasksCreate a SharePoint Sequential or State Machine workflow project within Visual Studio 2005.Add and configure activities on the WF design surface.Create any necessary custom forms (InfoPath or ASP.NET-based)Create a workflow.xml file.Create a SharePoint feature for deploying the workflow and custom forms (if any).
DemoWF Workflow Example Content SubmissionProcess the serial approval of an item within a document library.Upon approval, the document is automatically moved to a secured document library.
Custom SP Designer ActionsAllows custom logic to be leveraged in SP Designer workflows.All built-in actions within SP Designer are custom WF activitiesDefined in 12\TEMPLATE\1033\WORKFLOW\WSS.ACTIONSCustom actions are created within Windows WF Activity Library projects in Visual StudioNew actions require a one-time server deployment process, yet they can be leveraged on any SP Designer workflows that are developed.No client deployment is required.
Custom Action Development TasksCreate a new Workflow Activity Library project in Visual Studio 2005.Create 1 or more DependencyProperties for handing custom action inputs and outputs.Define custom execution logic using Workflow activities or by overriding the Execute method of the custom activity being developed.Create a .ACTIONS file (XML), describing the custom action.Deploy to 12\TEMPLATE\1033\WORKFLOWDeploy assembly to GAC and add an authorizedType entry in the web.config for it.
SP Designer Auto-PropertiesThe following properties, if defined on a custom SP Designer workflow action, are auto-populated with data at runtime.
Property NameAssigned Value.NET Data Type__ActivationPropertiesThe activation properties data for the running workflow instance.Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties__ListIdString containing the GUID for the list the workflow is defined on.System.String__ListItemInteger value for the list item the workflow instance is running on.System.Int32__ContextThe context object for the running workflow instance.Microsoft.SharePoint.WorkflowActions.WorkflowContext
DemoCustom SharePoint Designer Workflow ActionCreate sub-site using input parameters of Site Title and Site Description.
Wrap-upCustom-developed Windows WF solutions are supported on the SharePoint 2007 platform:Sequential & State Machine workflowsCustom activities (actions) for use in SP DesignerDecision factors to determine the technology to use:Developer skillsetsInformation Worker roles vs. Developer rolesReusability needsGovernance policies in placeQuestions?