Step by Step Tutorial : Creating workflows for Sharepoint 2010 : retrieving list items (step 2/15)

image_thumb

SharePoint 2010 workflow tutorial

  1. Step 1.
  2. Step 2.
  3. Step 3.
  4. Step 4.
  5. Step 5.
  6. Step 6.
  7. Step 7.
  8. Step 8.
  9. Step 9
  10. Step 10.
  11. Step 11.
  12. Step 12
  13. Step 13.
  14. Step 14.
  15. Step 15.

SharePoint 2007 workflow tutorial

  1. Step 1.
  2. Step 2.
  3. Step 3.
  4. Step 4.
  5. Step 5.
  6. Step 6.
  7. Step 7.
  8. Step 8.
  9. Step 9.
  10. Step 10.
  11. Step 11.
  12. Step 12.
  13. Step 13.
  14. Step 14.
  15. Step 15.
  16. Step 16.
  17. Step 17.

 

 

What we want to be able to do in this step  is retrieving the list item values (in our case the expense report information) associated with the running workflow : if the expense report is greater than 1000 then the manager approval will be required, otherwise the expense report will be accepted.

This post is based on the code (and site template) provided in Step 1.
This is straightforward in SharePoint : the OnWorkflowActivated activity has been databound with a workflow member called workflowProperties as illustrated in the next figure :

image

Figure 1

If we take a look at the associated .Net code, we will find the workflowProperties declaration :

image

Figure 2.

This workflowProperties member is an object created from the class SPWorkflowActivationProperties, which make the link between the workflow and the SharePoint context.

To analyze some of the properties of this SPWorkflowActivationProperties class, go back to the workflow designer in Visual Studio by clicking on the workflow file in the solution explorer and double click on the onWorkflowActivated1 activity.

An event handler will be generated in code behind; if you type workflowProperties follow by a dot (to trigger the Intellisense), you’ll discover some important properties like the current list item, the current list, the person who started the workflow, and much more :

image

Figure 3.

Let’s define a public member for each list column value we want to retrieve:

image

Go back to the workflow designer and drag and drop a new IfElse activity (from the Windows Workflow toolbox):

image

Figure 4.

Rename the ifElseActivity1 and each branch as follows:

image

Figure 5.

Select the ifSmallAmount activity, select the Condition Property in its property windows and choose Declarative Rule Condition.

image

Figure 6.

Set the Condition Name to SmallAmount:

 

image

Figure 7.

Click on the ellipsis button next to Condition Expression and add the following expression

image

Figure 8.

Click ok.

Drag and drop 2 code activities from the workflow foundation toolbox and rename them as Authorize and requestManagerApproval:

image

Figure 10.

Click on each code activity to generate an event handler and implement in authorize_ExecuteCode as follows:

image

Figure 11.

Deploy your workflow, add a new expense report with an amount value smaller than 1000, run the workflow and check the workflow status :

image

Figure 12.

Source code can be downloaded here.

4 responses to “Step by Step Tutorial : Creating workflows for Sharepoint 2010 : retrieving list items (step 2/15)

Leave a comment