Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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();
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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