6

I want to write a workflow which creates and updates tasks when the workflow item is changed. For example: the workflow-item has a multivalue field with users who should approve the workflow-item:

  1. When the item is created, the workflow has to create a task for each approver
  2. When the workflow-item is changed the workflow has to change the description of every task.

Part 1 (creation of multiple tasks) is more or less easy: I used a replicator activity (an example for this can be found in http://www.shillier.com/archive/2010/08/04/Creating_Multiple_and_Parallel_Tasks%20_in_SharePoint_2010_Workflow.aspx)

Part 2 (updating all tasks which were created in Part 1) is difficult:

I tried to write a CodeActivity, which iterates through all tasks and changes them via AlterTask-calls. This works perfect for the first time, but if I try to alter the same task a second time I get an exception, because the workflow has locked the task.

Another idea was to change the tasks with an UpdateTaskActivity. But this is difficult, because I have an arbitrary number of tasks and cannot define the right CorrelationToken for the UpdateTaskActivity.

Does anyone know a solution for this?

1 Answer 1

2

To prevent the error "This task is currently locked by a running workflow." try setting the WorkflowVersion of the task item to 1.

Example:

private void ResestTask(SPListItem task)
{
    // Remove the error "This task is currently locked by a running workflow."
    task[SPBuiltInFieldId.WorkflowVersion] = 1;

    // Update the task fields for example:
    task["Status"] = "In Progress";
    task.Update();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.