How to change the status of a sharepoint workflow task?

I am new to sharepoint programming. I have the following code:

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

and I get a 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 that I am doing something fundamentally wrong. Can anybody help me?

+4
source share
5 answers

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

And if you edited the columns in 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

+3
source

In fact, you can change the advanced properties of a task using the SPWorkflowTask.AlterTask method (task SPListItem, Hashtable htData method, bool fSynchronus). Hashtable contains advanced properties.

+1
source

In your SPWeb object, set AllowUnsafeUpdates = true. The error will disappear. Remember to set AllowUnsafeUpdates to false when you are done.

+1
source
0
source

You cannot adjust the Workflow task from outside the workflow. You must somehow inform the workflow in order to change the task. I am not 100% sure what the best approach would be, and I am really interested in answers to this :)

-1
source

All Articles