Step by Step Tutorial. Creating Workflows for Windows Sharepoint Services and MOSS2007 (part 2/20)

Step 2/20. Extending the workflow: checking the amount and setting the status

Download the code

The scenario

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 :


      public sealed partial class ExpenseReportWorkflow: SequentialWorkflowActivity
        public float Amount;
        public string Description;
        public string SubmittedBy;
        public string Status;

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.


            if (WorkflowProperties.Item["Amount"] != null)
                float.TryParse(WorkflowProperties.Item["Amount"].ToString(), out
            if (WorkflowProperties.Item["Description"] != null)
                Description = WorkflowProperties.Item["Description"].ToString();
            if (WorkflowProperties.Item["Status"] != null)
                Status = WorkflowProperties.Item["Status"].ToString();
                //Submitted By contains a space we need to use its internal name
                //WorkflowProperties.Originator is the submitter
                WorkflowProperties.Item["Submitted_x0020_By"] =


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:


        private void authorize_ExecuteCode(object sender, EventArgs e)
            WorkflowProperties.Item["Status"] = "Automatically Approved";


Double click on the requestManagerApproval activity and associate it with the following code :


        private void requestManagerApproval_ExecuteCode(object sender, EventArgs e)
            WorkflowProperties.Item["Status"] = "Automatically Approved";

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.


One response to “Step by Step Tutorial. Creating Workflows for Windows Sharepoint Services and MOSS2007 (part 2/20)

  1. Hi……..I can not debug my Workflow ……i did as u said in this article……but it shows "breakpoint will not currently be hit. No symbols have been loaded for this document."Kind Regards,Saurabh

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s