Search This Blog

Saturday, November 29, 2014

What is a Correlation Token-Workflow – ?-In HCL

Problem By Correlation Token:-



In approval workflow it is quite common to give the approver possibility to ask for additional information. When I develop sequential workflow I am modeling it the way this picture shows.



In other words first task "managementApproveTask" is creted and when the manager ask for additional information then "addManagementInfoTask" is created. Whene the person adds the information the big WHILE returns and creates new task for the manager to approve the document - this gives the manager the possibility to ask for additional information as many times as he wants and ask different people and so on...

Well then the question is which activity set as the owner of CorrelationToken of the CreateTask activity and also of OnTaskChanged activity - because they are always the same.

If you set the "ManagementApproveActivity" or any other activity PARENT TO THE WHILE loop as the owner of the CorrelationToken, you will get the following error:

System.InvalidOperationException: Correlation value on declaration "TOKEN NAME" is already initialized.
at System.Workflow.Runtime.CorrelationToken.Initialize(Activity activity, ICollection`1 propertyValues)
at System.Workflow.Activities.CorrelationService.InvalidateCorrelationToken(Activity activity, Type interfaceType, String methodName, Object[] messageArgs)...


The problem is as the exception says that the Correlation Token is already initialized. To resolve this you have to set as Owner activity of the CorrelationToken any activity inside the WHILE loop. Then any time the while loop is entered the activities inside are recreated, that means that there will be also new CorrelationToken created for each new task.


Workflow – What is a Correlation Token?

 Correlation tokenas a unique identifier that enables mapping between the objects in a workflow and the environment that is hosting the Windows Workflow Foundation (WF) workflow runtime.
You will have a separate correlation token for the each of the following:
  • The workflow itself
  • Each task you need to reference in the workflow
Declare the correlation token for the workflow in the OnWorkflowActivatedactivity. Then, for each activity that affects the entire workflow, bind that activity’s correlation token to the correlation token of theOnWorkflowActivated activity.

Correlation Tokens in SharePoint 2010 Workflow [WorkFlows in Visual Studio 2010]


One of the greate feature I found in the SharePoint is the Powerfull engine for developing the Workflows by visual studio 2010. some of the greate feature I love to capture in my blog, which help me out in future to remember whenever I need any one of them. The most immense topic is corelation properties.
I used Co-releatoin property in the BizTalk Server 2006, Still I quite impress with this Microsoft methodology to integrate different line of business. In sp 2010 again I am using the co-relation property in one of my workflow.
You can consider a correlation token as a unique identifier that enables mapping between the objects in a workflow and the environment that is hosting the Windows  Workflow Foundation (WF) workflow runtime.
Whenver you create a sequential workflow project in Visual Studio 2010 for SharePoint , it will prompt to ask name several times, which may confusion with which will be the workflow name.
There are actually three names that are used when creating workflows in Visual Studio 2010.
The first is the name of the project item,
second the name of the workflow itself—as defined in the Elements.xml file under the workflow project item folder
third is the name of the association.
(1) Create a new Project in Vs2010, Select SharePoint Template form left pane and Choose Sequential WorkFlow item from right pane.
Creating a Sequential workflow project
Creating a Sequential workflow project
(2) Deployed it as a Farm Solution because it is a site workflow.
Deployed as Farm Solution bcs its SiteWorkFlow which do not need any list to associate
(3) Choose a site workflow.
Choose it as site workflow bcs it no need to have any list
Choose it as site workflow bcs it no need to have any list


(4) Check History list to capture the history log of the workflow, And Task to Create Task in our workflow. Click Finish.
Setting WorkFlowHisotyList for History of WorkFlow
Setting WorkFlowHisotyList for History of WorkFlow
(5) Simple WorkFlow project has been created. Our First event on this WorkFlow is OnWorkFlowInitiated event.
Create a TaskToken as MyToken and Define the Task Id by Click on the Properties and also create an new GUID for our Task.
Simple Workflow Project Created, Drag Create Task method form ToolBox
Simple Workflow Project Created, Drag Create Task method form ToolBox
define the properties of the Task in the vs2010
define the properties of the Task in the vs2010
(7) Now Create new Task Properties.
Creating Task properties of mytask
Creating Task properties of mytask
(8) Generating Method Invoking Event to provide description and title for the task. We can also provide more detail regarding the Task but now we just put title and description, and mentioned new Guid for this Task.
methodEnvoking of MyTask event
methodEnvoking of MyTask event
setting the description and the title of our new Task
setting the description and the title of our new Task
co-relate the Workflow Task with onTaskChange Event
co-relate the Workflow Task with onTaskChange Event
(9) Drag a OnTeskChange event, and put name as WhenMyTaskChange.On the Properties set the Corelation Token as of TaskToken, so that both will be use a same uniuque corelation Id and set as MyTask_Id.
Define the Same Tasktoen with TaskChange event
Define the Same Tasktoen with TaskChange event
(10) Drag the Code Executer (Code Activity) on the design , and set the methodinvoking on which we are updating a content of our list. we can do anything with list, add update delete list , content type etc. Previously in BiZtalk server 2006 it CodeActivity was not there for this we used to add the classlibrary for data manipulation.
using execute code to update list
using execute code to update list
updating list very sime :)
updating list very sime :)
(11) Choose site workflow
going to site workflow
going to site workflow
out co-relation workflow
(12) Waiting for task to change, workflow status is Inprogress.
inprogress and wating for task to change
inprogress and wating for task to change
log history and of task in workflow
log history and of task in workflow
(13) Change the Content of Task to Change so that it will resume the workflow.
changing content of task to co-relation works
changing content of task to co-relation works
workflow complete when task change
workflow complete when task change





No comments:

Post a Comment