SharePoint 2010 workflow tutorial
- Step 1.
- Step 2.
- Step 3.
- Step 4.
- Step 5.
- Step 6.
- Step 7.
- Step 8.
- Step 9
- Step 10.
- Step 11.
- Step 12
- Step 13.
- Step 14.
- Step 15.
SharePoint 2007 workflow tutorial
- Step 1.
- Step 2.
- Step 3.
- Step 4.
- Step 5.
- Step 6.
- Step 7.
- Step 8.
- Step 9.
- Step 10.
- Step 11.
- Step 12.
- Step 13.
- Step 14.
- Step 15.
- Step 16.
- 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 :
Figure 1
If we take a look at the associated .Net code, we will find the workflowProperties declaration :
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 :
Figure 3.
Let’s define a public member for each list column value we want to retrieve:
Go back to the workflow designer and drag and drop a new IfElse activity (from the Windows Workflow toolbox):
Figure 4.
Rename the ifElseActivity1 and each branch as follows:
Figure 5.
Select the ifSmallAmount activity, select the Condition Property in its property windows and choose Declarative Rule Condition.
Figure 6.
Set the Condition Name to SmallAmount:
Figure 7.
Click on the ellipsis button next to Condition Expression and add the following expression
Figure 8.
Click ok.
Drag and drop 2 code activities from the workflow foundation toolbox and rename them as Authorize and requestManagerApproval:
Figure 10.
Click on each code activity to generate an event handler and implement in authorize_ExecuteCode as follows:
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 :
Figure 12.
Source code can be downloaded here.
Thanx for the nice posts.Waiting for the step 3/15.
thank you for your kind words !
Very clear explanation, and good tutorial
Three years people read this article and become more experienced. Thak you Luca!