26
Module 9: Workflow

Module 9 - Workflow

Embed Size (px)

Citation preview

Page 1: Module 9 - Workflow

Module 9: Workflow

Page 2: Module 9 - Workflow

Overview

Workflows in Microsoft SharePoint Products and Technologies

Workflow Life Cycle

Building Custom Activities

Building Custom Workflow Templates by Using Microsoft Visual Studio

Page 3: Module 9 - Workflow

What Is a Workflow?

Long Running : Days, Weeks, Months, Years

Serializable: Doesn’t have to be running the whole time

Resumable: Can be restarted when necessary

Page 4: Module 9 - Workflow

SharePoint and Workflow

SharePoint is a:

Persistence Engine – You don’t have to worry about where the workflow is stored

User Interface – Interact via the Web or through Microsoft Office system integration

Workflow brings process to SharePoint data

Page 5: Module 9 - Workflow

Differentiating Event Handlers and Workflow

Event Receiver

Lightweight

Short Running

Automatic Initiation

No User Interface

Workflow

Robust

Long Running

Automatic or User Initiation

Optional User Interface

Page 6: Module 9 - Workflow

Non-Developer Workflow Options

Out-of-the-Box Templates

Three Templates: Three State, Approval, Collect Feedback

Easy to use but flexibility is limited

SharePoint Designer

Easier to build than workflows with Visual Studio

Limited rules-based engine

Can not be moved between sites or between environments (not reusable)

Page 7: Module 9 - Workflow

Workflow Life Cycle

Developer develops a workflow template

Developer wraps workflow template in

Feature and Solution

Farm administrator deploys the workflow

solution

A Site Collection administrator activates the

workflow feature

Administrator creates a workflow

association with a list or content type

User or event starts a workflow

instance

Workflow executes activities and

optionally creates tasks and history

items

Optionally, the workflow owner

modifies the running workflow instance

Workflow completes

Page 8: Module 9 - Workflow

Workflow Forms

Association – When the workflow template is associated with a list

Instantiation – When a workflow instance is started

Workflow Modification Form – When the user wants to modify the flow of a running workflow

Workflow Status Form – The form displayed to the user to indicate the status of a workflow

Page 9: Module 9 - Workflow

Content Types and Workflows

Workflows can be associated with a content type

Workflow Tasks are a special content type (0x010801)

Content Types can have special new, display, and edit forms

Therefore, the task edit page for a workflow task can be customized

Page 10: Module 9 - Workflow

Development Environment

Microsoft Visual Studio 2005

Windows Workflow Foundation Extensions for the design experience

SharePoint Workflow Project templates

Microsoft Visual Studio 2008

Microsoft Visual Studio Tools for Microsoft Office

2008 delivers a workflow project template

Automates deployment and activation

Page 11: Module 9 - Workflow

Components of a Workflow

Simple Activities – Does something

Composite Activities – Coordinates other things

Custom Code (via Simple Activities) – Does everything else

Page 12: Module 9 - Workflow

Simple Workflow Activities

An activity is:

An atomic set of instructions used to complete a unit of work

A reusable component used to compose workflows

Activities are like controls in forms development

You drag and drop them onto a design surface

You modify their properties with property sheets

You generate event handlers and write code inside

Page 13: Module 9 - Workflow

Common Composite Activities

If Else

While

Sequence

Parallel

Page 14: Module 9 - Workflow

Writing Code in the Workflow

Code Activity

Contains one method to execute—thus providing a way to plug code directly into a workflow

Custom Developed Activity

Derive from the Activity class, override the Execute method, and deploy to the Global Assembly Cache (GAC)

Page 15: Module 9 - Workflow

The Workflow Project

Sequential Workflow

Predictable and fixed path for the workflow

Move from one activity to the other, possibly branch but flow is predefined

State Machine Workflow

Event-driven workflow

Events control theexecution of the activities

Page 16: Module 9 - Workflow

Model the Workflow

Drag and drop activities on the design surface

Service activities

Event activities

Code activities

Activities to branchthe workflow

Page 17: Module 9 - Workflow

SPWorkflowActivationProperties

Delivers SharePoint context information to your workflow code

Property bound to WorkflowProperties property of OnWorkflowActivated event activity

Access item information

Process association and initiation data

public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();

public double TotalAmount = 0;private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e){

TotalAmount = Convert.ToDouble(workflowProperties.Item["Total"]);}

Page 18: Module 9 - Workflow

Branch the Workflow

Define Rules

Code condition

Declarative condition

Page 19: Module 9 - Workflow

Code Activity

Basically empty activity

Connect your event handler executing custom code

private void SetApproved_ExecuteCode(object sender, EventArgs e){

workflowProperties.Item["ReportStatus"] = "Approved";}

Page 20: Module 9 - Workflow

Model of the Workflow

CreateTask activity

WhileActivity

OnTaskChanged activity

CompleteTask activity

Page 21: Module 9 - Workflow

Preparing a Task

Item based on Workflow Task content type

Inherits from Item content type

Additional fields to store workflow information

Event handlers

Hook up your own code with the event handlers and

Assign an ID

Set the properties of the task item

private void createTask1_MethodInvoking(object sender, EventArgs e){

Task1Id = Guid.NewGuid();Task1_Properties.Title = string.Format("Expenses of {0} to Approve",

workflowProperties.Item["Name"].ToString());string managerEmail = workflowProperties.Item["ManagerEmail"].ToString();string manager =

workflowProperties.Web.AllUsers.GetByEmail(managerEmail).LoginName;Task1_Properties.AssignedTo = manager;

}

Page 22: Module 9 - Workflow

While Loop

Code condition

Class-level variable in code is set to true if manager completes the task (setting percentage complete to 100%)

Exit the loop when condition is false

private void IsWaiting(object sender, ConditionalEventArgs e){

e.Result = !taskCompleted;}

Page 23: Module 9 - Workflow

Workflow Forms

Forms are used for configuring, initiating, and modifying workflows and completing tasks

Association Form, Initiation Form, Modification Form, and Task Edit Forms

ASPX Forms

Can be used by Windows SharePoint Services and Microsoft Office servers

Server-side only

InfoPath Forms (SharePoint Server or Microsoft Office Forms Server)

Server rendered by Microsoft Office Forms Server

Microsoft Office client integration

Write once, run server and client (same form)

Page 24: Module 9 - Workflow

ASPX Pages

Replace Windows SharePoint Services ASPX pages with custom ASPX pages in workflow feature

<Workflow Id="4797A6A6-4F31-40ca-9814-746402C2DB56" Name="Litware Approval"Description="Sample workflow template demonstrating workflow input forms"CodeBesideClass="LitwareWorkflows.LitwareApproval"CodeBesideAssembly="LitwareWorkflows, Version=1.0.0.0, Culture=neutral,

PublicKeyToken=74bad7277fe0d19e"AssociationUrl="_layouts/Litware/LitwareApprovalAssociation.aspx"InstantiationUrl="_layouts/Litware/LitwareApprovalInitiation.aspx"ModificationUrl="_layouts/Litware/LitwareApprovalModificationForm.aspx"TaskListContentTypeId="0x0108010084565D92BEFE4a75A28C2F658B7BECCA" ><MetaData><Modification_c7a53c4e-ab25-450f-a595-ae2b380d7c3e_Name>Modify workflow instance with a custom Litware form

</Modification_c7a53c4e-ab25-450f-a595-ae2b380d7c3e_Name></MetaData><Categories/>

</Workflow>

Page 25: Module 9 - Workflow

Typical Flow of Creating ASPX

Create ASPX with code-behind

Note that you have to manage all of the interaction between your page, Windows SharePoint Services, and the workflow engine

E.g., Creating the association, starting the workflow, serializing the data

Deploy ASPX in 12\Template\Layouts folder

Page 26: Module 9 - Workflow

Review

Workflows in Microsoft SharePoint Products and Technologies

Workflow Life Cycle

Building Custom Activities

Building Custom Workflow Templates by Using Microsoft Visual Studio