SharePoint Workflow Error: This task is currently locked by a running workflow and cannot be edited

Many times you were developing a Visual Studio workflow for SharePoint. You simply create a task using the “CreateTask” activity. After a while, you need to update the task and you do not have a valid correlation token to use the “UpdateTask” activity, for example, because you are creating a task inside a replicator (I will blog about this later). for example, inside your workflow you write…

SPListItem item = workflowProperties.TaskList.Items.GetItemById(id)
item[“Status”] = “Completed”;
item.SystemUpdate();

The last line will give you error “This task is currently locked by a running workflow and cannot be edited”, a possible work around for this issue, is to ensure that the workflow version number of the task is 1 before you update. Your code should look like the following…

SPListItem item = workflowProperties.TaskList.Items.GetItemById(id)
item[“Status”] = “Completed”;
item[SPBuiltInFieldId.WorkflowVersion] = 1;
item.SystemUpdate();

Happy Coding:)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.