Programmatically complete a workflow task

To complete a workflow task programmatically, use the following code (say taskItem is the task you want to complete):

taskItem.Web.AllowUnsafeUpdates = true;
Hashtable data = new Hashtable();
data[SPBuiltInFieldId.Completed] = “TRUE”;
data[SPBuiltInFieldId.PercentComplete] = 1;
data[SPBuiltInFieldId.Outcome] = “Completed”;
data[SPBuiltInFieldId.TaskStatus] = SPResource.GetString(new CultureInfo((int)taskItem.Web.Language, false), “WorkflowTaskStatusComplete”, new object[0]);
data[SPBuiltInFieldId.FormData] = SPWorkflowStatus.Completed;
SPWorkflowTask.AlterTask(taskItem, data, true);

This entry was posted in SharePoint 2010, Visual Studio 2010 and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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