pondělí 8. února 2010

Owner activity of CorrelationToken

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.

Žádné komentáře:

Okomentovat