client workflow labaz12722.vo.msecnd.net/office2010developertrainingcourse2...overview in this lab...

32
Hands-On Lab Client Workflow Lab version: 1.0.0 Last updated: 2/23/2011

Upload: others

Post on 12-Jul-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Hands-On Lab

Client Workflow

Lab version: 1.0.0

Last updated: 2/23/2011

Page 2: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

CONTENTS

OVERVIEW ................................................................................................................................................... 3

EXERCISE 1: DEFINING A PROCESS IN VISIO 2010 ............................................................................... 4 Task 1 – Define the Timesheet Approval process ................................................................................. 4

Task 2 – Export the process to SharePoint Designer ............................................................................ 7

EXERCISE 2: COMPLETING A PROCESS IN SHAREPOINT 2010 .......................................................... 8 Task 1 – Import the Visio process ......................................................................................................... 8

Task 2 – Complete the imported process ........................................................................................... 10

Exercise 2 Verification ......................................................................................................................... 16

EXERCISE 3: BUILDING A WORKFLOW IN VISUAL STUDIO 2010 ...................................................... 19 Task 1 – Create a new Visual Studio 2010 Sequential Workflow ....................................................... 19

Task 2 – Create the custom Association page..................................................................................... 23

Task 3 – Implement the TimeSheet generation workflow .................................................................. 27

Exercise 3 Verification ......................................................................................................................... 29

SUMMARY .................................................................................................................................................. 31

APPENDIX .................................................................................................................................................. 32 No Items 32

Page 3: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Overview

In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer 2010 and

Visual Studio 2010. The end goal of the workflow process is to approve timesheet submission. The

employee will submit an entry. The process will examine several fields and end up with an approved

timesheet. At this point, the data is used to generate a Word document containing a printable version

of the timesheet.

Objectives

In this lab you will:

Learn to build declarative workflows using Visio 2010 and SharePoint Designer 2010

Learn to build a workflow in Visual Studio 2010

System Requirements

This lab assumes that you have SharePoint Server installed in a test environment. For guidance on how

to setup SharePoint Server see http://msdn.microsoft.com/en-us/library/ee554869(office.14).aspx.

Note that any URL referred to in this lab must be adjusted for use with your local setup. You must have

the following items to complete this lab:

Microsoft® Windows® Vista SP1 or Microsoft® Windows Server 2008 (64-bit)

Microsoft® SharePoint Server 2010 (64-bit)

Microsoft® Office Professional Plus 2010 (32-bit or 64-bit)

Microsoft® Visual Studio 2010

Setup

You must perform the following steps to prepare your computer for this lab. This consists primarily of

creating a SharePoint site collection at http://intranet.contoso.com/sites/ClientWorkflow and

installing the code snippets for this lab.

1. Run the command file Setup.bat located at

C:\Office2010DeveloperTrainingKit\Labs\ClientWorkflow\Source\.

Page 4: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Visual Studio solutions. The lab provides a Source folder. The lab instructions assume that you

installed the training kit to the default location, C:\Office2010DeveloperTrainingKit\.

Note: Inside the lab’s Source folder, you will find a Solution folder containing an end solution

with the completed lab exercise.

Exercises

This Hands-On Lab is comprised of one exercise with the following tasks:

1. Defining a process in Visio 2010

2. Completing a process in SharePoint Designer 2010

3. Building a Workflow in Visual Studio 2010

Estimated time to complete this lab: 60 minutes.

Exercise 1: Defining a Process in Visio

2010

In this exercise you will use the Visio SharePoint Workflow template to define a process outline of the

Timesheet Approval process. This model can be exported to SharePoint Designer and server as a

starting point for the completion of the process.

Task 1 – Define the Timesheet Approval process

In this first task, you will define the process in Visio 2010 using the SharePoint Workflow template

1. Open Visio 2010 and create a new SharePoint Workflow drawing

a. Open Visio 2010

b. Choose the Flowchart template category and select the Microsoft SharePoint

Workflow template

c. Click the Create button to create the new drawing

Page 5: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Figure 1

Create new SharePoint Workflow

2. Add the Start and Terminate shapes to define the beginning and end of the process

a. Select the Quick Shapes section in the Shapes task pane

b. Drag a Start shape onto the new drawing

c. Drag a Terminate shape onto the new drawing

3. Add a Compare document field shape to check if the timesheet includes overtime

a. Select the SharePoint Workflow Conditions section in the Shapes task pane

b. Drag a Compare document field shape onto the drawing

c. Set the shape’s name to Check for Overtime

Figure 2

Check for Overtime shape

4. Add an Assign item for approval shape to submit the timesheet to the manager for approval

a. Select the SharePoint Workflow Actions section in the Shapes task pane

b. Drag a Start approval process shape onto the drawing

Page 6: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

c. Set the shape’s name to Send to Manager for Approval

Figure 3

Send to Manager for Approval shape

5. Add a Compare data source shape to check the results of the manager’s approval

a. Select the SharePoint Workflow Conditions section in the Shapes task pane

b. Drag a Compare data source shape onto the drawing

c. Set the shape’s name to Check for Approval

Figure 4

Check for Approval shape

6. Add a Set field shape to clear overtime if the manager rejected the overtime

a. Select the SharePoint Workflow Actions section in the Shapes task pane

b. Drag a Set field shape onto the drawing

c. Set the shape’s name to Clear Overtime

Figure 5

Clear Overtime shape

7. Connect the shapes to define flow of control

a. Connect the Start shape to Check for Overtime

b. Connect Check for Overtime to Send to Manager for Approval

c. Connect Check for Overtime to the Terminate shape

Page 7: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

d. Connect Send to Manager for Approval to Check for Approval

e. Connect Check for Approval to Clear Overtime

f. Connect Check for Approval to the Terminate shape

g. Connect Clear Overtime to the Terminate shape

Figure 6

Shape connection

8. Update all connections from decisions to be marked yes or no

a. Right click the connection between Check for Overtime and Send to Manager for

Approval and choose Yes

b. Mark the connection between Check for Overtime and the Terminate shape as No

c. Mark the connection between Check for Approval and the Terminate shape as Yes

d. Mark the connection between Check for Approval and Clear Overtime as No

e. Update the drawing’s layout to make it look like the image below

Figure 7

Shape connections with choices

Task 2 – Export the process to SharePoint Designer

In this task, you will export your Visio process so it can be loaded by SharePoint Designer. Once it is

loaded, it can be used as a starting point for the completed Timesheet Approval process.

1. Save the Visio process drawing

a. Click the Save button on the Quick Access Toolbar

Page 8: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

b. Set the folder to

C:\Office2010DeveloperTrainingKit\Labs\ClientWorkflow\Source\[language]\Start

er

c. Set the File name to Timesheet Approval.vsd and click Save

2. Export the process to SharePoint Designer

a. Click the Export button in the Process ribbon tab

b. Set the folder to

C:\Office2010DeveloperTrainingKit\Labs\ClientWorkflow\Source\[language]\Start

er

c. Set the File name to Timesheet Approval.vwi and click Save

Exercise 2: Completing a Process in

SharePoint 2010

In this exercise you will import the process exported from Visio and fill in the design details to create a

complete workflow.

Task 1 – Import the Visio process

In this first task, you will import the new process from Visio and create a new SharePoint Designer

workflow attached to the Timesheet content type.

1. Open the target SharePoint site in SharePoint Designer

a. Using Internet Explorer navigate to

http://intranet.contoso.com/sites/ClientWorkflow

b. Click Site Actions -> Site Settings

c. On the Site Settings page, click the Site collection features link

d. Activate the SharePoint Server Enterprise Site Collection features feature

Figure 8

Activated Site Collection Feature

e. Navigate back to the Site Settings page using Site Actions -> Site Settings

Page 9: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

f. Click the Manage site features link

g. Activate the SharePoint Server Enterprise Site features feature

Figure 9

Activated Site Feature

h. Click Site Actions -> Edit Site in SharePoint Designer

AdAdministrat

Figure 10

Edit in SharePoint Designer

2. Create a new workflow imported from Visio

a. Switch to the Workflows view using the Navigation bar on the left

b. Click the Import from Visio button in the Workflows ribbon tab

c. Browse to the Timesheet Approval.vwi file in the

C:\Office2010DeveloperTrainingKit\Labs\ClientWorkflow\Source\[language]\Start

er folder

d. Click Next to move to the next page of the wizard

e. Select the Reusable Workflow radio button

f. Choose Timesheet in the content type drop down list

Page 10: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Figure 11

Import Workflow Dialog

g. Click Finish to create the new workflow

Figure 12

Imported Workflow

Task 2 – Complete the imported process

In this task, you will use the process outline created by importing the Visio diagram as a starting point.

You will provide details to each task to complete the approval workflow.

1. Fill in the Check for Overtime task to check if the timesheet contains overtime hours

a. In the If statement under Check for Overtime, click the field link

b. Choose Overtime Hours in the field drop down list

c. Click the equals link and set it to is greater than

d. Click value and enter 0

Page 11: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Figure 13

Check if overtime approved

2. Initialize Send to Manager for Approval task

a. In the action under Send to Manager for Approval click the this item link

b. In the Choose List Item dialog, select Current Item and click OK

3. Define a custom Title to the approval message the manager receives

a. Click the these users link

b. Enter CONTOSO\Administrator in the Participants text box

c. Click the … button by the Title text box

d. Enter the text Overtime approval for into the text box

e. Click the Add or Change Lookup button

f. Select Employees in the Data source drop down list

g. Select Full Name in the Field from source drop down list

h. Select ID in the Field drop down list

Figure 14

Lookup Employee Full Name

i. Click the fx button by the Value text box

j. In the dialog, choose Employee in the Field from source

k. Choose Lookup Id (as integer) in the Return field as drop down list

Page 12: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Figure 15

Choose Employee ID

l. Click both OK buttons to return to the Select Task Process Participants dialog

Figure 16

Completed Approval subject

4. Define a custom message for the approval sent to the manager

a. Place the cursor into the Instructions text box

b. Click the Add or Change Lookup button

c. Choose Overtime Hours in the Field from source drop down list

d. Click OK to close the dialog

e. Add the following text after the lookup hours of overtime need approval

f. Click OK to complete the approval message definition

Page 13: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Figure 17

Completed Approval Definition

5. Update the Approval process to set an OvertimeApproved variable indicating the result

a. Click the Local Variables button on the Workflow ribbon tab

b. Click the Add button to add a new variable

c. Set the Name to OvertimeApproved and the Type to Boolean

Figure 18

Add Overtime Approved Variable

d. Click OK to create the new variable and click OK again to close the variables dialog

e. Click the Approval Process link in the Send to Manager for Approval action

f. Click the Change the behavior of a single task in the Customization section

g. Locate the When a Task Completes section

Page 14: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

h. Place the cursor after the first Log action and type Set Workflow Variable and press

Enter

Figure 19

On Task Completes Actions

i. Click the workflow variable link and choose Variable: OvertimeApproved

j. Click the value link and choose Yes

k. Repeat this process following the second Log action and set the variable to No

Figure 20

Overtime Approved Variable Set

6. Check the result of the approval and clear overtime hours if they were not approved

a. Navigate back to the primary workflow by clicking the Editor link in the header of the

window

Figure 21

Page 15: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Navigation to Workflow Editor

b. In the Check for Approval If statement, click the first value link

c. Click the fx button

d. Set Data source to Workflow Variables and Parameters

e. Set Fields from source to Variable: OvertimeApproved

Figure 22

Lookup Overtime Approved Variable

f. Click OK to close the dialog

g. Click the this test link and choose equals

h. Click value and choose Yes

Figure 23

Check if approval is complete

i. Click the field link in the Clear Overtime Set action and choose Overtime Hours

j. Click the value link and set it to 0

Figure 24

Clear overtime hours

Page 16: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

7. Set the workflow’s state to processed indicating the process is completed

a. Place the cursor after the Check for Overtime if statement and type Set workflow

status and press enter

b. Click the Canceled link and type Processed

Figure 25

Set workflow status

8. Change the workflow settings to show the Visio document in the status page and publish it to

SharePoint

a. Click the Workflow Settings link on the Workflow ribbon tab

b. Check the Show workflow visualization on status page checkbox

c. Click the Publish button on the Workflow Settings ribbon tab

d. Once the publish is complete, click Association to Content Type in the Workflow

Settings ribbon tab and choose Timesheet

e. Click OK to create the new workflow association

Exercise 2 Verification

In order to verify that you have correctly performed all steps of exercise 2, proceed as follows:

Test the Timesheet

Test your Timesheet.

1. Create a new Timesheet to approve

Page 17: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

a. In Internet Explorer navigate to http://intranet.contoso.com/sites/ClientWorkflow

b. Click the Timesheets link in the navigation menu

2. Create a new timesheet entry with less than 0 overtime hours

a. Click the New Item in the Items ribbon tab

b. Create a new item with the following items

i. Title – Amy Alberts Timesheet

ii. Employee – Amy Alberts

iii. Monday thru Friday Hours – 8

iv. Total Hours – 40

v. Overtime Hours – 0

c. Select the new item in the list and click the Workflows button in its drop down menu

d. In the Workflow page, click Timesheet Approval

e. In the initiation page, click Start to start the workflow

f. Click the Processed link to view the status

Figure 26

Completed with no Overtime

Note: Notice that the workflow completed immediately since there were no overtime

hours reported

3. Create a new timesheet entry with more than 0 overtime hours

a. Click the New Item in the Items ribbon tab

b. Create a new item with the following items

Page 18: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

i. Title – Alan Brewer Timesheet

ii. Employee – Alan Brewer

iii. Monday thru Thursday Hours – 8

iv. Friday Hours - 9

v. Total Hours – 40

vi. Overtime Hours – 1

c. Select the new item in the list and click the Workflows button in its drop down menu

d. In the Workflow page, click Timesheet Approval

e. In the initiation page, click Start to start the workflow

f. Click the In Progress link to view the status

Figure 27

Awaiting Overtime Approval

g. Click Edit Item in the Task’s drop down menu

h. In the task form, click the Reject button

Page 19: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Figure 28

Approve Overtime Task

i. When the task completes, navigate to the Timesheets list and verify the entry has no

overtime hours

Figure 29

Overtime Hours Cleared

Exercise 3: Building a Workflow in Visual

Studio 2010

In this exercise you will use Visual Studio to create a workflow that will use the timesheet data approved

in the previous examples and convert it to a Word document. The generated timesheet document will

be stored in a new document library that can be chosen when the workflow was associated.

Task 1 – Create a new Visual Studio 2010 Sequential Workflow

In this first task, you will create the sequential workflow item that will be the starting point for the

timesheet generation workflow.

1. Add a new Sequential Workflow item to the TimesheetApplication starter project

Page 20: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

a. Open Visual Studio 2010 and open the starter lab at

C:\Office2010DeveloperTrainingKit\Labs\ClientWorkflow\Source\[language]\Start

er\TimesheetApplication\TimesheetApplication.sln

b. Locate the Solution Explorer and see the SharePoint items already existing in the

solution

Figure 29(a)

Figure 29(b)

TimesheetApplication Solution

Note: Visual Studio 2010 allows the creation and management of SharePoint items,

features, and solutions in Visual Studio and deployment with a single menu option

Page 21: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

c. Right click TimesheetApplication in the Solution Explorer and select Add -> New

Item

d. In the Add New Item dialog, select the Visual C#\Visual Basic -> SharePoint -> 2010

template category and choose the Sequential Workflow item

e. Set the name to TimesheetGeneration and click Add to create the new workflow

item

Figure 30(a)

Figure 30(b)

Add New Sequential Workflow

Page 22: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

2. Using the SharePoint Customization Wizard, configure the site used for debugging

a. In the first page of the SharePoint Customization Wizard set the name to Timesheet

Generation

b. Verify the List Workflow radio button is selected and click Next

Figure 31

Set Workflow Name

c. Verify the check box indicating a workflow association should be created on

deployment is cleared and click Finish

Page 23: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Figure 32

Set Workflow Association Options

Note: An association will be created manually to test the Association page

Task 2 – Create the custom Association page

In this task, you will create a custom Association page that allows the user associating the workflow to

the Timesheet list to choose a document library to store the generated timesheet.

1. Add a new Association Form to the TimesheetGeneration workflow

a. Right click TimesheetGeneration SharePoint item in the Solution Explorer and click

Add -> New Item

b. In the Add New Item dialog, select the Visual C#\Visual Basic -> SharePoint -> 2010

template category and choose the Workflow Association Form item

c. Set the name to AssociationForm and click Add to create the form

Page 24: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Figure 33

Add New Association Form

d. Verify that the new AssociationForm.aspx file exists inside the

TimesheetGeneration SharePoint item

Figure 34(a)

Figure 34(b)

Workflow SharePoint Item

2. Define the layout of the page using custom ASPX markup

a. Open the AssociationForm.aspx page’s markup by right clicking it in the Solution

Explorer and selecting View Markup

b. Locate the asp:Content node with an ID of Main

Page 25: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

c. Place the following markup inside the asp:Content node to define a UI with a drop

down list containing all document libraries in the current site

i. Make sure the table is placed above the existing buttons

ASPX

<table>

<tr>

<td>Archive Document Library</td>

<td>

<asp:DropDownList ID="ArchiveLibrary" runat="server" />

</td>

</tr>

</table>

3. Implement the code behind that will populate and extract information from the ASPX page

a. Open the page’s code by right clicking it in the Solution Explorer and selecting View

Code

b. Add the follow code to the Page_Load method to check if this is the first load of the

form

C#

protected void Page_Load(object sender, EventArgs e)

{

bool initialLoad = false;

if (ViewState["associationParams"] == null)

initialLoad = true;

InitializeParams();

Visual Basic

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

Dim initialLoad As Boolean = False

If ViewState("associationParams") Is Nothing Then

initialLoad = True

End If

InitializeParams()

Note: Since the Association form’s initial load is a postback, a special viewstate

parameter is used to determine if this is the initial load.

c. Add the following code to Page_Load to load the DropDownList with all document

libraries in the current site

Page 26: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

C#

InitializeParams();

// Optionally, add code here to pre-populate your form fields.

if (initialLoad)

{

SPListCollection documentLibraries =

Web.GetListsOfType(SPBaseType.DocumentLibrary);

foreach (SPList documentLibrary in documentLibraries)

ArchiveLibrary.Items.Add(documentLibrary.Title);

Visual Basic

InitializeParams()

' Optionally, add code here to pre-populate your form fields.

If initialLoad Then

Dim documentLibraries As SPListCollection =

Web.GetListsOfType(SPBaseType.DocumentLibrary)

For Each documentLibrary As SPList In documentLibraries

ArchiveLibrary.Items.Add(documentLibrary.Title)

Next documentLibrary

d. Following the load of the drop down list, add the code to select the current archive

document library

C#

if (associationParams.AssociationGuid != Guid.Empty)

{

SPList list = Web.Lists[associationParams.TargetListGuid];

SPWorkflowAssociation association =

list.WorkflowAssociations[associationParams.AssociationGuid];

ArchiveLibrary.SelectedValue = association.AssociationData;

}

}

Visual Basic

If associationParams.AssociationGuid <> Guid.Empty Then

Dim list As SPList =

Web.Lists(associationParams.TargetListGuid)

Dim association As SPWorkflowAssociation =

list.WorkflowAssociations(associationParams.AssociationGuid)

ArchiveLibrary.SelectedValue = association.AssociationData

End If

}

Page 27: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

e. Add the following code to GetAssociationData to retrieve the name of the currently

selected item

C#

private string GetAssociationData()

{

return ArchiveLibrary.SelectedValue;

}

Visual Basic

Private Function GetAssociationData() As String

Return ArchiveLibrary.SelectedValue

End Function

Task 3 – Implement the TimeSheet generation workflow

In this task, you will implement the workflow process and add the custom activities to generate and

store the timesheet.

1. Add a new Code activity to the workflow that will generate the timesheet document

a. Open the workflow in the designer by right clicking

TimesheetGeneration.cs(TimesheetGeneration.vb in case of VB) in the Solution

Explorer and choosing View Designer

b. Locate the Code activity in the Windows Workflow v3.0 section of the Toolbox and

drag it onto the workflow following the existing application

c. Note: If the Toolbox is not visible, show it by clicking View -> Toolbox

Figure 35

New Code Activity

d. Select the new code activity, right click it and select Properties

e. In the Properties window, set the (Name) property to GenerateDocument

Page 28: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Figure 36

Code Activity Properties

2. Add the code behind to create and store the new timesheet document

a. Open the code behind for the GenerateDocument activity by double clicking it

b. In the new GenerateDocument_ExecuteCode method, add the following code to

generate the timesheet

C#

private void GenerateDocument_ExecuteCode(object sender, EventArgs e)

{

Timesheet timesheet = new Timesheet(workflowProperties.Item);

Visual Basic

Private Sub GenerateDocument_ExecuteCode(ByVal sender As Object, ByVal e

As EventArgs)

Dim timesheet_Renamed As New Timesheet(workflowProperties.Item)

c. Following the previous code, add the following code to lookup the archive document

library and write the timesheet into it.

C#

SPDocumentLibrary archiveLibrary =

workflowProperties.Web.Lists[

workflowProperties.AssociationData] as SPDocumentLibrary;

archiveLibrary.RootFolder.Files.Add(

workflowProperties.Item.Title + ".docx",

timesheet.WriteTimesheet());

}

Visual Basic

Dim archiveLibrary As SPDocumentLibrary =

TryCast(workflowProperties.Web.Lists(workflowProperties.AssociationData)

, SPDocumentLibrary)

Page 29: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

archiveLibrary.RootFolder.Files.Add(workflowProperties.Item.Title

& ".docx", timesheet.WriteTimesheet())

}

Note: The workflowProperties.AssociationData property is initialized by the

OnWorkflowInitialized activity. The value is stored in the SPWorkflowAssociation

object based on the association data stored in the Association form.

3. Deploy the solution by right clicking TimesheetApplication in the Solution Explorer and clicking

Deploy

Exercise 3 Verification

In order to verify that you have correctly performed all steps of exercise 3, proceed as follows:

Test the Workflow

Execute your workflow and verify it converts the timesheet list item into a new document in the

selected document library.

1. Associate the new Timesheet Generation workflow with the Timesheets

a. In Internet Explorer, navigate to

http://intranet.contoso.com/sites/ClientWorkflow/Lists/Timesheets

b. In the List ribbon tab, click Workflow Settings -> Add a Workflow

c. In the Workflow list, select Timesheet Generation and enter a name of Timesheet

Generation

Figure 37

Workflow Association Form

d. Click Next to move to the custom association form.

e. In the custom association form, select Timesheet Archive in the drop down list and click

Association Workflow to complete the association

Page 30: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Figure 38

Custom Association Form

2. Execute the new workflow to generate a new Timesheet Word document

a. In Internet Explorer, navigate to

http://intranet.contoso.com/sites/ClientWorkflow/Lists/Timesheets

b. Select a timesheet in the list and click the Workflows button in its drop down menu

Figure 39

Item Menu

c. In the Workflow page, click Timesheet Generation to start the process

d. When the workflow is completed navigate to

http://intranet.contoso.com/sites/ClientWorkflow/ TimesheetArchive and verify a

new timesheet document has been created

Figure 40

Timesheet Archive Document Library

e. Click the document’s drop down menu to open the document in Word and verify it

contains the timesheet data

Page 31: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Figure 41

Generated Timesheet Document

Summary

In this exercise you learned how to automate your business processes using the workflow offerings in

SharePoint 2010. First, Visio 2010 was used to define the rough outline for a business process which

was exported to SharePoint Designer 2010 for completion. The action based interface of SharePoint

Designer 2010 allowed for simple creation of a process that could be completed by a IT Professional.

Once the first process was in place, a more complex process which included custom code was created

using Visual Studio 2010 and the SharePoint workflow tools.

Page 32: Client Workflow Labaz12722.vo.msecnd.net/office2010developertrainingcourse2...Overview In this lab exercise, you will build a workflow process using Visio 2010, SharePoint Designer

Appendix

No Items

No Appendix content