views:

5834

answers:

4

Hi,

I am novice in sharepoint programming. I have a following code:

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

and I am getting 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

I believe I am doing something fundamentally wrong. Can anybody help me?

A: 

You can not modify a Workflow Task from outside the workflow sadly. You somehow have to tell the workflow to modify the task. I'm not 100% sure what the best approach to that would be, and I'm really interested in answers for that as well :)

Michael Stum
+3  A: 

here is an expert comment on this problem : http://geek.hubkey.com/2007/09/locked-workflow.html

And, if you have edited the columns on the task list, this link may help : http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/8ec834b6-5408-4079-bdfb-b88d341b36bf/

hope this helps

Onur Bıyık
+1  A: 

Actually you can modify task extended properties using SPWorkflowTask.AlterTask(SPListItem task, Hashtable htData, bool fSynchronus) method. Hashtable here contains Extended properties.

+1  A: 

In your SPWeb Object, set AllowUnsafeUpdates = true. The error will go away. Remember to set AllowUnsafeUpdates to false when you are done.