Saturday, March 12, 2011

Task Assignment Using Workflows

In this exercise you will extend the previous workflow to implement the basic Task assignment process using Visual studio2010.

1. Open (Previous Post)in visual studio 2010:

clip_image002

2. Add a new CreateTaskActivity between onWorkflowActivated1 and logToHistoryListActivity1 from the SharePoint Workflow section of the toolbox.

clip_image004

3. Right Click on CreateTaskactivity Select Properties.

clip_image006

clip_image008

4. The first thing needed here is a correlation token for the task. A correlation token is used for message correlation in workflow. It provides a unique identifier that enables a mapping between a task object in a specific workflow instance and the workflow runtime in SharePoint. This is used so that when SharePoint receives a message for the workflow instance it can locate the correct task within the correct workflow instance. The CorrelationToken property must be configured and it’s not recommended to use the WorkflowToken for tasks, although this isn’t prevented in the tool. Enter the new name for the correlation token as TaskToken and press enter. Then expand the (+) symbol which appears and click the drop down to the right of OwnerActivityName and choose the workflow1.

clip_image009

5. The TaskId must be configured and a new GUID specified for the task id. This is done by selecting the TaskId property and clicking the […] ellipsis to bring up the property editor. Click the Bind to a new member tab, choose Create Field, and then click OK. The same must be done for the TaskProperties property by again selecting the property, clicking on the ellipsis and adding a new field.

clip_image011

clip_image013

6. Double click on the new CreateTask activity on the workflow design surface to bring up the createTask1_MethodInvoking handler code and set the properties in code.

clip_image014

7. Place the following code inside the createTask1_MethodInvoking method. The new task must be given a title, and for good measure. Specify user to whom task would be assigned, here we are assigning task to user who is initiating workflow.

{

createTask1_TaskId1 = Guid.NewGuid();

createTask1_TaskProperties1.Title = “MyTask ";

createTask1.TaskProperties.AssignedTo = workflowProperties.OriginatorUser.LoginName;

}

clip_image016

8. Add a new onTaskChanged1 following Createtask1Activity1 from the SharePoint Workflow section of the toolbox.

clip_image018

9. To configure the OnTaskChanged, you need to wire up the CorrelationToken and the TaskId properties to the same fields as the CreateTask1. This is done by selecting the TaskId property and clicking the […] ellipsis to bring up the property editor click bind to existing member and select Create_Task1_TaskId1 and click ok.

clip_image019

clip_image020

10. Add a new CompleteTask following Createtask1Activity1 from the SharePoint Workflow section of the toolbox.

clip_image022

11. To configure the OnTaskChanged, you need to wire up the CorrelationToken and the TaskId properties to the same fields as the CreateTask1. This is done by selecting the TaskId property and clicking the […] ellipsis to bring up the property editor click bind to existing member and select Create_Task1_TaskId1 and click ok.

clip_image019[1]

clip_image023

This is consistent throughout SharePoint workflow.

clip_image025

12. Deploy the workflow to SharePoint and verify that it works.

Ø Right click the project in solution explorer and click Deploy.

Ø When the deployment is complete, open Internet Explorer and navigate to http://servername/Lists/TestList/AllItems.aspx.

13. Click the drop down menu on one of the Item in the list and select Workflows.

clip_image027

14. Click the WorkFlowLab1-Workflow-1 link to start the workflow.

clip_image029

15. Click the In Progress link under WorkFlowLab1-Workflow-1 to track the workflow.

clip_image031

16. Click on Task mentioned in Task List notice task is assigned to work flow initiator.

clip_image033

17. Click on Edit Item.

clip_image035

18. Set Status = Completed and percentage to 100% then click Save button.

clip_image037

18. Notice that status of both task and workflows are set to Completed and history log activity that is last activity of workflow has been executed.so this is the end of Exercise-2 with successful task assignment workflow.

clip_image042

Comments

0 comments:

Post a Comment