25
Workflow

Work Flow

  • Upload
    ngp77

  • View
    79

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Work Flow

Workflow

Page 2: Work Flow

Workflow

Table of Contents

Workflow .............................................................................................................................. 1

Exercise 1 Creating the workflow .................................................................................................................................. 2

Exercise 2 Building Workflows with SharePoint Designer 2010 .................................................................................... 7

Exercise 3 Developing Workflows with Visual Studio 2010 ......................................................................................... 18

Exercise 4 Adding Association Forms in Visual Studio 2010 ........................................................................................ 21

Page 3: Work Flow

Workflow

Page 1 of 23

Workflow

Objectives After completing this lab, you will be better able to:

Use Visio to create the high level process

Export the Visio model to SharePoint Designer 2010

Use SharePoint Designer 2010 to complete the detail

Export from SharePoint Designer 2010 to a WSP file

Import the WSP file into Visual Studio 2010

Scenario

The Office 2010 platform has a new level of integration between the different

workflow development tools. Visio 2010, SharePoint Designer 2010, and Visual

Studio 2010 can all work together to create a complete workflow. By combining

all three, power users and developers can work together to structure an

organization’s processes.

Estimated Time to Complete This Lab

60 Minutes

Computers used in this Lab demo2010a

The password for the Administrator account on all computers in this lab is: pass@word1

Page 4: Work Flow

Workflow

Page 2 of 23

Exercise 1 Creating the Workflow

Scenario

In this first exercise you will setup the workflow and add a task process.

Tasks Detailed Steps

Complete the following tasks on:

demo2010a

1. Lab Setup Instructions

a. Start the Virtual Machine in Hyper-V.

b. Log on to the Virtual Machine as the local administrator with a user name of Contoso\Administrator and a password of pass@word1.

c. Open Windows Explorer and browse to the location C:\student\Labs\08_Workflow, in the folder double-click SetupLab08.bat.

d. Verify the site created successfully message, and then press [Enter] to close the prompt. The setup script launches a PowerShell script that creates a sample SharePoint site at the location http://intranet.contoso.com/sites/Lab08 that you will use in the next exercises.

Page 5: Work Flow

Workflow

Page 3 of 23

Tasks Detailed Steps

2. Create a Workflow in Visio 2010

Note: In this task you will use Microsoft Visio to design a workflow. You will then save this drawing and use it in SharePoint Designer in the next Exercise.

a. Click Start | All Programs | Microsoft Office | Microsoft Visio 2010. Microsoft Visio starts.

b. Click Cancel at the Microsoft Office Activation Wizard prompt, if shown.

c. In the Template Categories In the middle of the screen click Flowchart.

d. In the list Available Templates, click Microsoft SharePoint Workflow and press [Enter].

e. In the SharePoint Workflow Terminators section, drag a Start shape to the left of the diagram.

Page 6: Work Flow

Workflow

Page 4 of 23

Tasks Detailed Steps

f. In the SharePoint Workflow Terminators section, drag a Terminate shape to the right of the diagram.

g. Expand the SharePoint Workflow Conditions.

h. In the SharePoint Workflow Conditions section, drag a Compare Data Source shape to the diagram.

i. Double-click the newly added shape and change the name to Check if manager approval is needed.

j. If the SharePoint Workflow Action category isn’t visible, click the separator bar between the shapes and the categories and drag it down.

k. In the SharePoint Workflow Action section, drag a Log to History List shape to the diagram.

l. Double-click the newly added shape and change the name to Log Manager approval required.

m. In the SharePoint Workflow Action section, drag a Log to History List shape to the diagram and release under the last shape.

Page 7: Work Flow

Workflow

Page 5 of 23

Tasks Detailed Steps

n. Double-click the newly added shape and change the name to Log automatically approved.

o. In the SharePoint Workflow Action section, drag a Log to History List shape to the diagram and release to the right of the last two shapes.

p. Double-click the newly added shape and change the name to Log submission to HR.

q. Hover over the source shapes, click and drag an Arrow to the target shapes. The diagram should look as follows:

r. Right-click the connection from Check if manager approval is needed to Log Manager approval required and select Yes.

s. Right-click the connection from Check if manager approval is needed to Log automatically approved and select No.

t. Click the Save icon, and save the process diagram to C:\Student\Labs\08_Workflow\lab with a filename of Timesheet Submission Workflow.vsd

u. In the menu click Process, and then in the ribbon click Export.

Page 8: Work Flow

Workflow

Page 6 of 23

Tasks Detailed Steps

v. Save the exported workflow to C:\Student\Labs\08_Workflow\lab and provide the name Timesheet Submission Workflow.vwi

w. Leave Visio open, you will return to it later in this lab.

Page 9: Work Flow

Workflow

Page 7 of 23

Exercise 2 Building Workflows with SharePoint Designer 2010

Scenario In this exercise you will import the Visio workflow into SharePoint Designer and complete it. This includes defining the parameters of each step as well as adding some new steps. At the end you will publish your complete workflow and export it back to Visio.

Tasks Detailed Steps

Complete the following tasks on:

demo2010a

1. Adding Logic with SharePoint Designer

a. Click Start | All Programs | SharePoint | SharePoint Designer 2010. Microsoft Office SharePoint Designer 2010 starts.

b. Click Cancel at the Microsoft Office Activation Wizard prompt, if shown.

c. In the Open SharePoint Site section, click Open Site. The Open Site dialog appears.

d. In the Site name textbox, type http://intranet.contoso.com/sites/lab08

e. Click Open.

f. Click cancel if you are prompted at a permission prompt. SharePoint Designer opens.

g. In the left hand navigation bar, click Workflows.The Globally Reusable workflows are displayed.

Page 10: Work Flow

Workflow

Page 8 of 23

Tasks Detailed Steps

h. On the ribbon, click Import from Visio

i. In the Import Workflow from Visio Drawing click Browse and open the folder C:\Student\Labs\08_Workflow\lab

j. In the folder click Timesheet Submission Workflow.vwi and then click Open.

k. On the Import Workflow from Visio Drawing dialog, click Next.

l. In the Workflow name textbox, verify the name is Timesheet Submission Workflow.

m. In the Choose the type of workflow to import as, click Reusable Workflow.

n. In the Run on items inheriting from this type Dropdown list, select Time Sheet.

o. Click Finish to import the workflow. The Timesheet Submission workflow is displayed. Review this workflow – it is the workflow you defined in Visio.

Page 11: Work Flow

Workflow

Page 9 of 23

Tasks Detailed Steps

Page 12: Work Flow

Workflow

Page 10 of 23

Tasks Detailed Steps

2. Creating Local Variables

Note: In this task you will create local variables to store the maximum number of hours before approval is required and the employee name.

a. On the ribbon, click Local Variables.

b. In the Workflow Local Variables dialog box, click Add.

c. In the Name textbox, type EmployeeName

d. In the Type dropdown list, click String.

e. Click OK.

f. Click Add.

g. In the Name textbox, type MaxHours

h. In the Type dropdown list, click Integer.

i. Click OK.

j. In the Workflow Local Variables dialog, click OK.

3. Setting Workflow Variables

Note: In this task you will set the workflow variables. For the EmployeeName you will first set an EmployeeID. This will be replaced later with the employee’s real name requested from the HR System.

a. Place the cursor just above the first If statement in the workflow.

b. On the ribbon, click Action and then click Set Workflow Variable.

c. Click the Workflow Variable link and click Variable:EmployeeName.

d. Click the Value link and click the [fx] button

Page 13: Work Flow

Workflow

Page 11 of 23

Tasks Detailed Steps

e. In the Data Source dropdown list, click Current Item.

f. In the Field from source dropdown list, click EmployeeID.

g. Click OK.

h. Place the cursor just below the action you have added and before the first If statement in the workflow

i. On the ribbon, click Action and then click Set Workflow Variable.

j. Click the Workflow Variable link and select Variable:MaxHours.

k. Click the Value link, type 40 and press [Enter].

l. In the first If statement, click the first value hyperlink and then click the [fx] button.

m. In the Data Source dropdown list, click Current Item.

n. In the Field from source dropdown list, click Hours.

o. Click OK.

p. Click the this test hyperlink and click is greater than.

Page 14: Work Flow

Workflow

Page 12 of 23

Tasks Detailed Steps

q. Click the second value hyperlink and then click the [fx] button.

r. In the Data Source dropdown list, click Workflow Variables and Parameters.

s. In the Field from source dropdown list, click Variable:MaxHours.

t. Click OK to close the dialog.

u. In the Log manager approval required section, click the this message hyperlink, and click the ellipses button […]

v. In the String Builder dialog, type the text The time sheet for

w. Leave a space at the end of this text.

x. Click the Add or Change Lookup button. The Lookup for string dialog appears.

y. In the Data Source dropdown list, click Workflow Variables and Parameters.

z. In the Field from source dropdown list, click Variable:EmployeeName.

aa. Click OK.

bb. Finish the message by typing requires manager approval.

Page 15: Work Flow

Workflow

Page 13 of 23

Tasks Detailed Steps

cc. Click OK to close the dialog.

dd. In the Log automatically approved section Click the this message hyperlink, and click the ellipses button […]

ee. In the String Builder dialog, type the text The time sheet for

ff. Leave a space at the end of this text.

gg. Click the Add or Change Lookup button. The Lookup for string dialog appears

hh. In the Data Source dropdown list, click Workflow Variables and Parameters.

ii. In the Field from source dropdown list, click Variable:EmployeeName.

jj. Click OK.

kk. Finish the message by typing does not require manager approval.

ll. Click OK to close the dialog.

mm. In the Log submission to HR item, click the this message hyperlink, and type The time sheet has been submitted to HR.

nn. Press [Enter].

oo. In the workflow breadcrumb, click theTimesheet Submission Workflow.

pp. In the Settings section, enable the Show workflow visualizations on status page checkbox.

qq. In the ribbon, click Publish.

rr. Launch Internet Explorer and open http://intranet.contoso.com/sites/Lab08

ss. Move to Site Site Actions - Site Settings – Site Content types– Locate Time Sheet content type and click it

tt. Click Workflow settings

uu. Click Add a workflow

Page 16: Work Flow

Workflow

Page 14 of 23

Tasks Detailed Steps

vv. Select Time Submission workflow from list box and name that as Submission

ww. Click OK

xx. Click Time Sheet from the breadcrumb to move back to content type settings page

yy. Click Document Information Panel settings

zz. . Check the Always show Document Information Panel… checkbox

aaa. Click OK

Page 17: Work Flow

Workflow

Page 15 of 23

Tasks Detailed Steps

4. Test Visio Web Access for workflow status view

a. Move to front page of the http://intranet.contoso.com/sites/Lab08 site

b. In the Quick Launch bar, click Timesheets.

c. On the ribbon tab, click Documents Tab.

d. On the ribbon, click New Document then OK. The new document loads.

e. In the EmployeeID textbox, type 1

f. In the Hours textbox, type 38

g. Click Save and close the document

h. If prompted for credentials type contoso\administrator and pass@word1. Ensure the properties have saved properly. In the current VM they may be removed. If so right-click the document and Edit Properties.

i. In the new document’s dropdown menu, click Workflows.

j. Click Submission Workflow. The initiation page loads

k. On the initiation page, click Start.The workflow will start.

l. In the Timesheet list click the completed link on the item and review the Workflow History.

m. In the Quick Launch bar, click Timesheets.

Page 18: Work Flow

Workflow

Page 16 of 23

Tasks Detailed Steps

n. On the ribbon tab, click the Documents Tab.

o. On the ribbon, click New Document then OK. The new document loads

p. In the EmployeeID textbox, type 1

q. In the Hours textbox, type 42.

Note: this value requires workflow requires approval.

r. Click Save.

s. Provide a unique document name, for example, Doc2.

t. Verify the properties are saved and close the document.

u. In the Doc2.docx dropdown menu, click Workflows.

v. Click Submission Workflow.

w. The initiation page loads

x. On the initiation page, click Start. The workflow will start.

y. In the Timesheet list click the completed link on the item and review the Workflow History. Keep in mind you will need to approve the task for a timesheet with hours greater than 40.

Page 19: Work Flow

Workflow

Page 17 of 23

Tasks Detailed Steps

5. Synchronizing Changes with Visio

a. Switch back to SharePoint Designer and verify the workflow is still in the active window.

b. In the ribbon, click Export to Visio.

c. Save the updated .vwi file to C:\Student\Labs\08_Workflow\Lab\Timesheet Submission Workflow.vwi Note this is separate location where the original file is

d. Switch to Microsoft Visio.

e. On the Process ribbon, click Import.

f. Select the C:\Student\Labs\08_Workflow\Lab\Timesheet Submission Workflow.vwi file. The Visio diagram is now updated to include the Set Workflow Variable task added in SharePoint Designer.

Page 20: Work Flow

Workflow

Page 18 of 23

Exercise 3 Developing Workflows with Visual Studio 2010

Scenario

In this exercise you will build a workflow in Visual Studio 2010 that submits the timesheet information to the back

end HR system and places the payment reference back into the original time sheet.

Tasks Detailed Steps

Complete the following tasks on:

demo2010a

1. Creation workflow project

a. Open Visual Studio 2010 and create a new workflow project:

b. Select the Sequential Workflow template in the Visual C# " SharePoint " 2010 templates folder and give it the name VSSubmissionWorkflow.

c. Set location as c:\student\labs\08_Workflow

d. Verify the URL. The workflow should be deployed to http://intranet.contoso.com/sites/Lab08. Indicate that the workflow must be deployed as a farm solution.

e. In the wizard set the workflow name to Timesheet Submission VS and select the List Workflow radio button. Click the Next button.

f. Clear the check box indicating a workflow association should be created on deployment. An association will be created manually to test the association page.

Page 21: Work Flow

Workflow

Page 19 of 23

Tasks Detailed Steps

g. Click the Finish button.

h. Add a new Code Activity from the Windows Workflow v3.0 section of the toolbox.

i. Add it immediately following the onWorkflowActivated1 activity.

j. Set the name of the new code activity to SubmitToHR using the Properties window.

k. Double-click the activity to generate the ExecuteCode event handler.

l. Add the following code to simulate the calculation of a payment reference using a Guid, to be sure to have a unique reference. Save this reference in the time sheet on which the workflow runs.

private void SubmitToHR_ExecuteCode(object sender, EventArgs

e)

{

SPListItem item = workflowProperties.Item;

item["Payment Ref"] = Guid.NewGuid().ToString();

item.Update();

}

Page 22: Work Flow

Workflow

Page 20 of 23

Tasks Detailed Steps

2. Deployment of workflow

a. Setup the auto association parameters that will tell Visual Studio to automatically associate your workflow with the Time Sheets list when it is deployed.

b. Select Workflow1 in the solution explorer.

c. In the Properties window, set the Auto Associate property to True.

d. In the History List property click the [...] button to start the wizard.

e. Click Next and select a list of Time Sheets in the first dropdown and click Next.

f. On the final page check the first check box and clear the rest and click Finish.

g. Right click the project in solution explorer and click Deploy.

h. When the deployment is complete, open Internet Explorer and navigate to http://intranet.contoso.com/sites/Lab08/Lists/TimeSheets.

i. Click the drop down menu on one of the documents in the list and select Workflows.

j. Click the Timesheet Submission VS link to start the workflow.

k. When the workflow is complete verify the Payment Ref was assigned and then click the Completed link of the Timesheet Submission VS column.

l. Verify the workflow history.

Page 23: Work Flow

Workflow

Page 21 of 23

Exercise 4 Adding Association Forms in Visual Studio 2010

Scenario In this exercise you will add an association form to the timesheet submission workflow. This form will allow

configuring an hourly rate.

Tasks Detailed Steps

Complete the following tasks on:

demo2010a

1. Adding Association Forms in Visual Studio 2010

a. Move back to Visual Studio

b. Add a new association form to the Workflow1 workflow.

c. Right click on the Workflow1 folder and click Add >>New Item.

Note: Make sure that you select the workflow node and not the project node because you will be able to add an association form but it will never be associated with the workflow.

d. Select Workflow Association Form from Visual C# >> SharePoint >> 2010, name it AssociationForm.aspx and click Add.

e. In the asp:Content control with the ID of Main, add the following markup to create the page just above the AssociateWorkflow button.

<table>

<tr>

<td>Hourly rate:</td>

<td>

<asp:TextBox ID="HourlyRateTextBox"

runat="server" />

</td>

</tr>

</table>

f. Right click the markup window and choose View Code.

g. Add the following code to GetAssociationData method to save the hourly rate settings to the association data. Replace the comment and base class call

private string GetAssociationData()

{

double rate = 0.0;

double.TryParse(HourlyRateTextBox.Text, out rate);

return rate.ToString();

}

h. Open Workflow1 in the designer.

i. Drag a new code activity from the toolbox and drop it between the onWorkflowActivated1 activity and the SubmitToHR activity.

j. Rename the activity to InitializeAssocData.

Page 24: Work Flow

Workflow

Page 22 of 23

Tasks Detailed Steps

k. Double-click the InitializeAssocData activity to generate the event handler.

l. Add the following code to retrieve the association data from the association form and to calculate the due amount based on the hours filled out on the time sheet and the hourly rate specified in the association form.

private void InitizalizeAssocData_ExecuteCode(object sender,

EventArgs e)

{

// retrieve the association data from the association form

OnWorkflowActivated activity =

this.Activities["onWorkflowActivated1"] as

OnWorkflowActivated;

string associationData =

activity.WorkflowProperties.AssociationData;

// retrieve the hourly rate from the association data

double amountToPay = 0.0;

double.TryParse(associationData, out amountToPay);

// retrieve the list item

SPListItem item = workflowProperties.Item;

// get the hours on the timesheet

int hours = 0;

int.TryParse(item["Hours"].ToString(), out hours);

// calculate and save the amount to pay

item["Payment Amount"] = amountToPay * hours;

item.Update();

}

m. For the purpose of saving time in this lab, go to C:\Student\Labs\08_Workflow\Solution\VSSubmissionWorkflow and double click VSSubmissionWorkflow.sln and deploy the workflow to SharePoint by right clicking the project in solution explorer and clicking Deploy.

n. Click Yes to overwrite

o. Use the new association page to fill out an hourly rate.

p. Open Internet Explorer and navigate to http://intranet.contoso.com/sites/Lab08/Lists/TimeSheets.

Page 25: Work Flow

Workflow

Page 23 of 23

Tasks Detailed Steps

q. Click Library Settings in the Library ribbon tab.

r. Click the Workflow Settings link in the Permissions and Management section.

s. Click the Timesheet Submission VS link to manage the workflow association.

t. Click Next to view the custom association page.

u. Enter a value an amount and click Association Workflow.

v. Navigate back to http://intranet.contoso.com/sites/Lab08/Lists/TimeSheets

w. Use the drop down menu on a timesheet for second document (Doc2) on the list and choose Edit Properties link to change the hours to 35.

x. Save changes

y. Click the drop down menu on one of the documents in the list and select Workflows.

z. Click the Timesheet Submission VS link to start the workflow.

aa. When the workflow is complete, you should see that a payment amount is calculated.

Related Resources: Microsoft SharePoint Server 2010 Trial Download