More on Building Workflow using VS 2010

These are a few notes I took from reading the Workflow materials in the book “MS Sharepoint 2010 – Building Solutions for Sharepoint 2010” by Sahil Malik, on building Workflow using Visual Studio 2010. The notes are mainly for myself to remind me some of the details so they might not make sense for others.

In codeActivity1, a random number is generated as soon as the workflow starts. The workflow is associated with the “Task” list.

This is the code.

Now we want to use the random number to decide what the new task title should be. If it’s 1, 2, then title is “Small Task”; 3, 4, then “Medium Task”; 5, 6, then “Hugh Task”.

So we will need to drag an IfElse Activity from under “Windows WorkFlow 3.0” Toolbox to under codeActivity1, so you will get this:

Under ifElseActivity1 there are two ifElseBranchActivities. I am guessing the first ifElseBranch (ifElseBranchActivity1) is the IF part, and the second ifElseBranch (ifElseBranchActivity2) is the ELSE part, and that’s why only the first one has an exclamation mark because you normally have to specify the condition for the IF part. Whatever doesn’t pass the IF condition check will go to the ELSE part, which is ifElseBranchActivity2.

Since inthis case I have 3 conditions (1-2, 3-4 and 5-6) so I attempt to “add” another ifElseBranchActivity. So select and right click the ifElseBranchActivity2, do a Copy and Paste, and then I get this:

So I will use the first branch for check 1-2, the second for 3-4 and thrid one will be whatever doesn’t satisfy the previous two, which is 5-6.

Since we have work to do in each of these 3 conditions, so we need to drag a task to each BranchActivity. Drag UpdateTask (createTask will actually create another new task. But we just want to update the current task, so use UpdateTask) from under Sharepoint Workflow to where it says “Drop Activities Here:.

So you get this:

Again the exclamation marks indicate that we need to enter some code to make them actually do something.

So to set the condition for the first BranchActivity, click on it and look in the Properties pane for “Condition”. It says “(None)”. Click the cell and select “Declarative Rule Condition” since we have a very simple condition that can be achieved by just using declaration. Expand the “Condition” by clicking the arrow next to it. You see “Condition Name” and “Expression”. Give a name and click the eclipse in the Expression.

in the “Rule Condition Editor”, specify the condition (rolled dice = 1 or 2)

In the end it should look like this:

Right now you will see the exclamation mark on top of the first BranchActivity is gone.

Do the same thing for the second BranchActivity so it checks for dice value f 3 or 4. Skip the third BranchActivity as it’s the ELSE part.

Now we will handle the task in each of three BranchActivities. The createTask inside each BranchActivity will be executed only if the condition specified in the BranchActivity is satified.

Click the first updateTask and look into the Properties pane for “Correlation Token”. Whatever it is, according to an MSDN page, you will need a separate correlation token for the following: (1) the workflow itself and (2) each task you need to reference in a workflow. (

So we will need a new correlation token for each updateTask. Simply type in a string next the Correlation Token, such as “Check1and2Token”, and click the arrow next to “Correlation Token” to to display the “OwnerActivityName” property. According to Mahil Salik, you can select any parent as the Owner; so we will just select “Workflow1”. This is it:

There’s more – at the bottomof the Properties pane, look for TaskID and TaskProperties.

For eachof the two, click on the Eclipse and bring up the “Bind…..” dialog box. Click the “Bind to a new member” tab, and select “Create Field” and click OK to close it.

After that:

Do the same thing to the other two updateTasks. Now we need to code the updateTasks so the “Task” list title can be updated based on the dice value. Double click the first updateTask to switch to the code view. Enter the following code (slightly modified from Sahil’s code in the book) —

Add similar code to the other two updateTasks so the title can be updated to “Medium Task” and “Huge Task” respectively.

Save, build and deploy the solution to Sharepoint 2010 server.

Post a comment or leave a trackback: Trackback URL.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: