By Serge Luca
Step 2/20. Extending the workflow: checking the amount and setting the status
Click here to get to the previous article.
What we want to implement here is retrieving the list item : the expense report informations; if the expense report is greater than 1000 then the manager approval will be required, otherwise the expense report will be accepted.
Retrieving the expense report details
This is straightforward in Sharepoint : we just need to bind the OnWorkflowActivated activity with a workflow member:
Select the OnWorkflowActivated1 activity,
Select its workflowProperties in the property page and Click on the ellipsis button,
Select the tab Bind to a new member
Select Create Field, and set Workflowproperties as the new field name:
A new Data member of type Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties will be generated and linked to the activity information. Among others this class will provide access to the list item via its Item property.
Add 4 new public data members to the ExpenseReportWorkflow class :
Double click on the Invoked event of the onWorkflowActivated1 activity :
A new event handler, onWorkflowActivated1_Invoked, will be generated: we will retrieve the expense report values at this level.
Debugging the workflow
Let’s compile your changes and call the install.bat file. Call your web site to start the w3p.exe process.
Set a breakpoint in the onWorkflowActivated_Invoked event handler and attach the assembly to the w3p.exe process (Debug menu-Attach to Process, select w3p.exe).Go to the ExpenseReports list , start the workflow until you hit your breakpoint in the debugger and watch your data members :
Checking the values and setting the status
Drag and drop an ifElse activity and rename the activities as following:
In the ifSmallAmount activity, select the Declarative Rule Condition for the condition property:
Enter SmallAmount as the ConditionName :
Click on the ellipsis (…) button and the rule editor will show up.
Type the following condition:
You’ll notice that a .rules file has been generated this file contains expressions describing or rules / conditions. The language for these expressions is CodeDom. We’ll get back to this
Drag and drop 2 code activities and rename them as follows:
Double click on the Authorize activity and associate it with the following code:
Double click on the requestManagerApproval activity and associate it with the following code :
Start install.bat and test the workflow on your list item:
Test the workflow with amounts greater than 1000.
This hands-on training is the property of Redwood S.L sprl and may not be organized in class or in group without the prior written permission of Serge Luca. Should you wish to organize this hands-on training in your company or institution, please contact Serge Luca first to enter into a licence agreement. Each trainer or teacher using this hands-on training should have a licence agreement. Please ask your trainer or Serge Luca whether he or she has entered into a licence agreement with Redwood S.L sprl.
The hyperlink to this hands-on training may be placed on your website for free, on the condition that the name Serge Luca is clearly mentioned in the reference. Please send us a mail containing the link to the web page our reference is used on.