{"id":744,"date":"2012-01-14T15:27:45","date_gmt":"2012-01-14T15:27:45","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=744"},"modified":"2012-01-14T15:29:02","modified_gmt":"2012-01-14T15:29:02","slug":"task_locked_running_workflow_cannot_be_edited","status":"publish","type":"post","link":"https:\/\/www.stuartroberts.net\/index.php\/2012\/01\/14\/task_locked_running_workflow_cannot_be_edited\/","title":{"rendered":"Task locked by Running Workflow and Cannot be Edited"},"content":{"rendered":"<p>If you&#8217;re trying to update a task item that is linked to a running workflow using code similar to<\/p>\n<pre lang=\"csharp\">\r\npublic UpdateTaskItem(SPList taskList, int identifier, string newValue)\r\n{\r\n  taskItem = taskList.GetItemById(identifier);\r\n  \/\/ Update task item\r\n  taskItem[\"fieldname\"] = newValue;\r\n  taskItem.Update();\r\n}\r\n<\/pre>\n<p>and receive an error stating <em>This task is currently locked by a running workflow and cannot be edited<\/em>, a simple fix is to update the built in field WorkflowVersion to the value 1 prior to calling the <em>Update<\/em> method.<br \/>\n<!--more--><\/p>\n<pre lang=\"csharp\">\r\npublic UpdateTaskItem(SPList taskList, int identifier, string newValue)\r\n{\r\n  taskItem = taskList.GetItemById(identifier);\r\n  \/\/ Update task item\r\n  taskItem[\"fieldname\"] = newValue;\r\n  \r\n  Guid workflowInstanceId = new Guid(taskItem[Microsoft.SharePoint.SPBuiltInFieldId.WorkflowInstanceID].ToString());\r\n  SPWorkflow workflow = taskItem.Workflows[workflowInstanceId];\r\n  if (workflow != null && !workflow.IsLocked)\r\n  {\r\n    taskItem[Microsoft.SharePoint.SPBuiltInFieldId.WorkflowVersion] = 1;\r\n  }\r\n  \r\n  taskItem.Update();\r\n}\r\n<\/pre>\n<p>Setting this field to 1 allows the task item to be updated.  There&#8217;s a check performed by SharePoint to see if this field&#8217;s value is set to 1 and when it&#8217;s not, the <em>This task is currently locked by a running workflow and cannot be edited<\/em> error is thrown.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re trying to update a task item that is linked to a running workflow using code similar to public UpdateTaskItem(SPList taskList, int identifier, string newValue) { taskItem = taskList.GetItemById(identifier); \/\/ Update task item taskItem[&#8220;fieldname&#8221;] = newValue; taskItem.Update(); } and &hellip; <a href=\"https:\/\/www.stuartroberts.net\/index.php\/2012\/01\/14\/task_locked_running_workflow_cannot_be_edited\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[3,82],"tags":[81,39,6],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/plx2I-c0","_links":{"self":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/744"}],"collection":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/comments?post=744"}],"version-history":[{"count":5,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/744\/revisions"}],"predecessor-version":[{"id":762,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/744\/revisions\/762"}],"wp:attachment":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}