如何更改sharepoint工作流任务状态?

时间:2008-12-16 14:58:07

标签: sharepoint workflow

我是sharepoint编程的新手。我有以下代码:

SPWorkflowTask  task = some_getter();
task["Status"] = "Canceled";    
task.Update();

我收到了SPException:

Microsoft.SharePoint.SPException: "This task is currently locked by a running workflow and cannot be edited."
at Microsoft.SharePoint.SPListItem.PrepareItemForUpdate(Guid newGuidOnAdd, Boolean bMigration, Boolean& bAdd, Boolean& bPublish, Object& objAttachmentNames, Object& objAttachmentContents, Int32& parentFolderId)
at Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents)
at Microsoft.SharePoint.SPListItem.Update()
at mycode

我相信我做的事情根本就是错误的。有人能帮助我吗?

5 个答案:

答案 0 :(得分:3)

这是对此问题的专家评论:http://geek.hubkey.com/2007/09/locked-workflow.html

并且,如果您已在任务列表中编辑了列,则此链接可能有所帮助:http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/8ec834b6-5408-4079-bdfb-b88d341b36bf/

希望这会有所帮助

答案 1 :(得分:1)

实际上,您可以使用SPWorkflowTask.AlterTask(SPListItem task,Hashtable htData,bool fSynchronus)方法修改任务扩展属性。此处的Hashtable包含扩展属性。

答案 2 :(得分:1)

在SPWeb对象中,设置AllowUnsafeUpdates = true。错误将消失。完成后,请记住将AllowUnsafeUpdates设置为false。

答案 3 :(得分:0)

您需要将任务项的SPBuiltInFieldId.WorkflowVersion属性设置为1 我在这里写了博客:http://blogs.technet.com/b/meamcs/archive/2011/03/26/workflow-error-this-task-is-currently-locked-by-a-running-workflow-and-cannot-be-edited.aspx

答案 4 :(得分:-1)

您无法从工作流程外部修改工作流任务。你不得不告诉工作流程修改任务。我不是百分之百确定最好的方法是什么,我也非常感兴趣的答案:)