Step by Step Tutorial. Creating Workflows for Windows Sharepoint Services and MOSS2007 (part 12/20). Managing several approvers/reviewers

image

Step by Step Tutorial. Creating Workflows for Windows Sharepoint Services and MOSS2007 (part 12/20). Managing several approvers/reviewers

 

By Serge Luca

MVP Connected System 

image

 

 

Introduction

The Out-of the box approval workflow provided with MOSS allows to specify several approvers. In this post, I will illustrate how to do this. In a first time (part 1) , I will show you how to use the Replicator activity that you will need, and in a second time (part 2), you will apply this knowledge to our Sharepoint problem. If you know how the Replicator activity works you can directly go to part 2.

 

Part 1. Using the Replicator activity

The Replicator activity is part of the Workflow Foundation Base Activity Library, is somewhat similar to the While activity.

  • Create a  Sequential Workflow console application project.
  • Add a Replicator activity into the workflow surface

image

  • Add a custom Activity to the project; call it "ManageTask":

 

image

  • Define a public string member  called Approver in the custom activity :

 

image

  • Drag and drop a Code activity in the custom activity

image

  • Display the Approver member in its Event handler:

image

Recompile the project and drag & drop the custom activity into the Replicator:

image

  • In the workflow code add an ArrayList data member and name it Approvers :

image

  • In the Workflow constructor, add 2 users to the ArrayList

image

  • In the Replicator activity, databind the InitialChildData property to the ArrayList:

image

In the Replicator activity, double click on the ChildInitialized event to generate an event handler :

image

  • Each item in the collection will be associated with a child activity (the child activity here is ManageTask): each time a child activity will be created, the ChildInitialized event will be triggered, which give us the possibility to pass the associated data :

image

Run the application:

image

You can download the code here.

Part 2. Using the Replicator activity in the Approval workflow

 

  • as I did in the previous post, I will start by using the HelloWorldSequential sample  provided with the MOSS sdk. Don’t forget to replace the string http://locahost in the install.bat file with you own web site/site collection url. (See step 11 of this tutorial for more infos about this sample).

 

  • The strategy is to replicate the following selected activities in a Replicator activity :

 

image

We will group these activities in a custom sequential activity.

  • Add a new project (Sharepoint-Sequential Workflow Library ) to the current solution

image

  • Remove the following files from the project :

image

  • In the same project, add a new custom activity, name it ManageApproval:

image

  • You can either drag & drop the activities from Workflow1 to the new custom activity or adding new activities in the ManageApproval activity (my option) :

 image

  • Link each of these activity to the same correlation token : TaskToken and ManagerApproval for the OwnerActivityName

image

  • Select the CreateTask activity and databind its TaskId and TaskProperties property to  new fields :

TaskId and TaskProperties

  • Databind the TaskId prperty of the OnTaskChanged and CompleteTask activities to the newly created taskId member.

On the OnTaskChanged activity, databind the AfterProperties and BeforeProperties to new fields:

AfterProperties and BeforeProperties

image

  • Define the following members (make sure Assignee is public since it will get the task owner from the Replicator activity) :

image 

  • Double click on the CreateTask activity to generate a handler and add the following code:

(most of the code can be copied from Workflow1.cs)

image

  • Set the Condition property of the WhileActivity to Code Condition and name the function TaskNotFinished :

image

  • Define a bool data member, isFinished , and check its status in the TaskNotFinished function:

image

  • Double click on the TaskChanged activity to generate a handler and add the following code:

image

  • Sign you assembly
  • Get back to the workflow project and double click on the workflow code to display it in the designer; clean it up by deleting the activities you don’t need anymore; you must have something like this:

image

  • Recompile the solution to make sure your custom activity will show up in the toolbox.
  • Add a Replicator activity just after the OnWorkflowActivated activity and drag & drop you custom activity in it.

image

  • In the workflow code, define a new member to host the assignees:

image

  • Store the assignees into this ArrayList: click on the OnWorkflowActivated activity and add the following code in the handler:

image

  • Bind the Replicator activity to the Assignee member.
  • Add a handler to the ChildInitialized event of the Replicator and insert the following code:

image

  • Modify the install.bat file in order to register the custom activity in the Gac :

"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -uf MyApprovalActivities
"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -if bin\Debug\MyApprovalActivities.dll

 

  • Test the workflow: rebuild, install the workflow, add the association and start a workflow ; assign to user separated with a ";" , for instance  U2UCOURSE\Administrator;U2UCOURSE\serge, like this :

image

A first task will be created for the user "Administrator":

image

  • If the Administrator clicks on its task :

image

  • Then, if the user "Administrator" select the "I am finished reviewing" and click the Submit button, a new task will be created for the user "serge":

image

 

  • The reason  Serge’s tasks is created after the Administrator’s task completes is that the ExecutionType property of the Replicator activity was set to Sequence. Let’s change it to parallel, rebuild and test the workflow .

image

Congratulations !!!!


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.


About these ads

11 responses to “Step by Step Tutorial. Creating Workflows for Windows Sharepoint Services and MOSS2007 (part 12/20). Managing several approvers/reviewers

  1. Thank you for the Tutorial, very helpful.
     
    I\’ve got a question that I hope you would be able to help me with,
    In your tutorial a the point where you are checking whether the OnTaskChanged event has been edited to end the loop, how can I make it so that the while loop only ends when the task status is set to completed?
     
    Any help would be greatly appriciated.

  2. Hi, your tutorial has been very helpfully to me!!!
    I have a question: It is possible to create dynamically tasks in a State Machine Workflow?? I dont know how to use the Replicator Activity in a State Machine WF.

  3. Hi Serge, I create a solution with two projects, one is a Sharepoint sequential workflow and another is a Workflow Activity like as your example, but when i debug the application the Sharepoint sequential workflow execute the ChildInitilized method and when finish execute the basic create task sequence, in sharepoint i see 5 task assigned to the last approver, and the Sharepoint sequential workflow finish and don\’t wait approvers appove the task. why is this problem? any solution?

  4. Hi Serge,
      Maybe this isn\’t the best place to start learning about custom workflow coding, but your tutorial appeared to be thorough enough so I gave it a go…  My first problem I ran into is that my custom activity ManageTask can not be dragged and dropped into the replicator.  I started from scratch and did not attempt to use your code example.  I guess I\’ll download the example, but I must be missing something important in my set-up or in my choices when setting up the project.  I am using Visual Studio 2008 standard.  I added my custom activity by right clicking on the project in solution explorer and then add and then activity.  I rebuilt the project like you said and it errored because there is no activity in the replicator so I tried to drag and drop and it gives me the old NOT symbol.
     
    Do I need to install the sdk or something… I haven\’t done that.
     
    Thanks.

  5. Ok, I see now that the project files are not studio 2008 version so I guess I\’ll have to find some different examples or figure out how to make this work in 2008.

  6. I was able to get through the replicator portion by embedding a sequential activity rather than creating a separate custom activity and trying to drag it onto the workflow.  This meant that everything was embedded in the workflow code so, I will definitely have some learning to do in regards to creating re-usable activities.

  7. Hi, friend. I am from china chongqing, thank you provide\’s tutorial. It is very good and utility. Hope you can continue write tutorial.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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