locked
The reassign funtion in workflow RRS feed

  • Question

  • Hi all,
    I have  created a custom workflow of  approval for WSS in VS2005, and I receive  some error when I reassign the task to other people. Like the following:

    10/7/2007 5:02 PM Error  System Account
        at  System.Workflow.Runtime.CorrelationToken.Initialize(Activity activity, ICollection`1 propertyValues)
        at System.Workflow.Activities.CorrelationService.InvalidateCorrelationToken(Activity activity, Type interfaceType, String methodName, Object[] mes           Outcome: Workflow Completed!


    some code as following:

            //task fields
            public Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties taskProperties = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
            public Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties taskAfterProperties = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
            public Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties taskBeforeProperties = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
            public Guid taskId = default(System.Guid);
            public String ExecutingUser = default(System.String);
            public String TaskOutcome = default(System.String);
            public Guid TaskStatusFieldId = new Guid("c15b34c3-ce7d-490a-b133-3f4de8801b76");
            public string TaskStatus = default(string);
            public string Comments = "";

            // history list fields
            public String HistoryDescription = default(System.String);
            public String HistoryOutcome = default(System.String);

    private void createTask1_MethodInvoking(object sender, EventArgs e)
            {
                //generate ID for task
                taskId = Guid.NewGuid();
               
                //assign initial values for task creation
                this.task_not_completed = true;
                taskProperties.Title = "Approval required for " + ItemName;
                taskProperties.Description = this.Instruction;
                taskProperties.AssignedTo = ExecutingUser;
                taskProperties.PercentComplete = 0;
                taskProperties.StartDate = DateTime.Today;
                taskProperties.DueDate = DateTime.Today.AddDays(2);
                taskProperties.ExtendedProperties["WorkflowOutcome"] = "";
                this.EnsureUserIsRecognized(ExecutingUser);
            }


    I don't know how to solve this problem.Does anyone know how to fix it?
    Thanks
    Alan
        
    • Edited by Mike Walsh FIN Monday, July 19, 2010 3:00 AM Don't add ... at end of titles
    Sunday, October 7, 2007 9:53 AM

Answers

All replies

  • Hi Alan

     

    This code looks like your creating the task for the first time, not reassigning it.

     

    Also, the error indicates an issue with the correlation token. Are you creating a new token for the task?

     

    Regards

    Mike

    Monday, October 8, 2007 10:01 AM
  • Hi Mike

    The createTask activity is inside a while activity, and I want to reassign the task to other perple, so I set

     the while condition ture.Then it will create a task again,but there is an error:

      HistoryDescription: Correlation value on declaration "taskToken" is already initialized.

    The "taskToken" was set when designing the workflow logic. And  in the create task method, i didn't

     create a new token.


    I am so sorry that my english is poor.  I don't know whether you can  understand me or not.
    Monday, October 8, 2007 11:07 AM
  • Hi Alan

     

    Ok, I think I can see whats going wrong here. Your workflow is trying to create a new token for the task with the same name as your workflow token, which explains your error. Create a new correlation token using the same workflow but name it something like task1token. Each task will need to use a different token to your workflow token.

     

    Also remember to complete each task before re-assigning it otherwise you may get the same error again or lots of uncompleted tasks.

     

    Regards,

    Mike

    Monday, October 8, 2007 11:28 AM
  • Hi Mike
        I know that each task  need to use a different token, but how to do that while the workflow designed like the following:

    sequenceActivity1
        whileActivity1
    ->sequenceActivity2
              ->createTask1
    ->onTaskChanged1
    ->completeTask1

    And in the method InitializeComponent()  include the following code:

    correlationtoken1.Name="taskToken";
    correlationtoken1.OwnerActivityName="sequenceActivity1";

    createTask1.CorrelationToken=correlationtoken1
    onTaskChanged1.CorrelationToken=correlationtoken1;
    completeTask1.CorrelationToken=correlationtoken1;

    In the situation, how to ensure  I had a different token while creating a new task for the re-assigning  approver?....

    Regards,

    Alan
    Tuesday, October 9, 2007 8:05 AM
  •  

    Hi Alan,

     

    As your using VS2005 you can easily create new correlation tokens by using the design view. Using the design view look at the properties of the CreateTask activity. You'll be able to see Correlation Token, and a + to expand to view the OwnerActivityName - this your workflow name.

     

    Change the name of the token to something like "task1Token" and make sure your workflow is still selected under the OwnerActivityName, if not you should be able to use the down arrow to re-select it. On your TaskComplete activity you need to select the token you just created.

     

    Reassining the task to another user can be done in two ways; either reassign the same task or complete the current task and create a new task for the new user with exactly the same details as the previous one. Using the same task should just be a case of changing the MyTask.AssignedTo field to the new user but I've not tested this.

     

    Your alternative is to complete the current task and create a new task for the user its to be reassigned to. Here I'd put the CreateTask, OnTaskChanged and CompleteTask activities within the while loop. The OnTaskChanged activity would check if the task is to be re-assigned or not and control while loop condition.

     

    Hope this helps.

    Mike

    Tuesday, October 9, 2007 8:47 AM
  • Hi Mike
        Have you tested that reassigning to other user in the second way you mentioned above?  
    Thursday, October 11, 2007 3:44 AM
  • What I understand is when we put a createtask activity inside the while activity, the second time it executes the createtask activity will trigger the correlation token already initialised problem. It is because the token is already initialised for the first time execution and we have no way to assign a new token to it at runtime nor uninitialised the token.

    It seems that there is no way to dynamic create new task at runtime, but the approval workflow which comes with sharepoint server 2007 did demonstrate that effect.

    Thursday, October 11, 2007 8:22 AM
  • Im also feeling it. There is no way to reassign task. But in SharePoint Approval workflow it demonstrate this function. Then their should be way for it. But how .... ??? 
    Wednesday, October 29, 2008 10:03 AM
  • Hi,

    I need to develop Re Assigning Task workflow using Visual Studio or Sharepoint Designer for my Sharepoint project, Could you please guid how can i achive this.

     

    Thanks

    Siva


    kumar
    Monday, July 12, 2010 6:47 PM
  • Look at this video:

    http://www.sheltonblog.com/archive/2007/11/01/how-to-video-programmatically-escalating-an-overdue-task-document-workflow.aspx

    See how he is escalating the task, using the updatetaskactitvity. I think this is what you are looking for

    The key is tu update the assigned to of the task, i did this on other workflows. What i didn´t is create another task when reassign, i don´t know how to do that because the problem of the correlation token, but you could use the same task and update the assigned to...


    asd
    Tuesday, July 13, 2010 1:30 AM
  • Note (Important : First Time Activities complete with Correction token defined in the work design, if the Task is reassigning then it will not work, for that we have to put all the Activities(Create Task, Task changes, complete Task) inside the sequential activities and changes the OwnerActivity to sequenceActivity1) that’s it.

    for more information, Look at my site

    http://sites.google.com/site/sharebyme/sharepoint/workflow/workflow-with-infopath/reassigningtask


    kumar
    Sunday, July 18, 2010 1:46 PM
  • Note (Important : First Time Activities complete with Correction token defined in the work design, 


    Yeah. That is correct. Thanks a lot. Finally got the answer for 1 Year and 8 months old problem :)
    • Edited by Mike Walsh FIN Tuesday, July 20, 2010 10:53 AM Don't use full quote
    Tuesday, July 20, 2010 10:44 AM
  • If you want to reassign the task do this in the task change method.  OnTaskChanged

    if (this.TaskStatus.Equals(TaskStatusType.Reassigned))
                    {
                // update variable to be in the while loop
                        this.TaskNotComplete = true; // (This is the variable you used in the while loop set it so that wile loop will continue)

                        // do not update WorkflowOutcome field
                        string strAssignedTo = this.TaskAfterProperties.AssignedTo.ToString();
                        string strSPReviewer = this.GetFormattedSPUser(strAssignedTo);
                        string strOldReviewer = this.GetUser(this.WorkflowProperties.Item, this.WorkflowProperties.Item.Fields[ItemFiledType.Reviewer]).LoginName;
                        item[ItemFiledType.Reviewer] = strSPReviewer;
                        if (this.TaskAfterProperties.ExtendedProperties[ItemFiledType.EShuttleComments] != null)
                        {
                            item[ItemFiledType.Comments] = this.TaskAfterProperties.ExtendedProperties[ItemFiledType.EShuttleComments].ToString();
                        }
                        item.SystemUpdate(false);

                
                        // update WorkflowOutcome field & properties
                        this.SetWorkflowPropertiesFromTaskChanges(TaskStatusType.Reassigned, TaskStatusType.NotStarted, true);
    }


    Call the the alter task again and changes the assigned to in the task after properties.
    Tuesday, July 20, 2010 11:53 AM