Here is my code to programmatically alter the task at hand, the only problem is that the code doesn't alter the "Outcome" of the approval task. The Outcome field is blank. "Task Status" is Complete, but the Outcome is empty for that task under the workflow status.

Also, under the Task list, the task at hand is 100% complete and set to Completed

Hashtable data = new Hashtable();
            data["FormData"] = SPWorkflowStatus.Completed;
            data[SPBuiltInFieldId.Completed] = "TRUE";
            data["Completed"] = "TRUE";
            data[SPBuiltInFieldId.PercentComplete] = 1.0f;
            data["PercentComplete"] = 1.0f;
            data["Status"] = "Completed";
            data[SPBuiltInFieldId.TaskStatus] = SPResource.GetString(new CultureInfo((int)task.Web.Language, false),
                                                                    Strings.WorkflowStatusCompleted, new object[0]);
            data[SPBuiltInFieldId.WorkflowOutcome] = "Approved";
            data["TaskStatus"] = "Approved"; 
            data["ows_FieldName_Comments"] = "Approved by " + user.Name + "\n";
            web.AllowUnsafeUpdates = true;
            SPWorkflowTask.AlterTask(task, data, true);
  • were you able to get this working? Commented Apr 26, 2013 at 22:00
  • No, something leads me to believe it is the build I have that prevents these changes... support.microsoft.com/kb/2737435
    – Mike
    Commented Apr 29, 2013 at 13:13

3 Answers 3


I was able to get this working using this blog and I think you have the incorrect assignment to data["TaskStatus"].

Set ht["TaskStatus"] = "#" to set task outcome as “Approved”
Set ht["TaskStatus"] = "@" to set task outcome as “Rejected”

    // alter the task
    Hashtable ht = new Hashtable();
    ht["Status"] = "Complete";
    ht["PercentComplete"] = 1.0f;
    ht["TaskStatus"] = "#";
    SPWorkflowTask.AlterTask((taskedit as SPListItem), ht, true);
  • tried both ways...
    – Mike
    Commented Apr 29, 2013 at 13:12

In SharePoint 2013 there is no need to use alter the task.

Directly access the list Workflow Tasks and update the item. Following code worked for me:

using (SPSite _site = new SPSite(spSiteURL))
                    using (SPWeb _web = _site.OpenWeb())
                            _site.AllowUnsafeUpdates = true;
                            SPList _taskList = _web.Lists[spTaskListName];
                            SPListItem _taskItem = _taskList.GetItemById(8);
                            if (_taskItem != null)
                                _web.AllowUnsafeUpdates = true;
                                _taskItem["TaskOutcome"] = "Approved";
                                _taskItem["PercentComplete"] = "1";
                                _taskItem["Status"] = "Completed";
                                _web.AllowUnsafeUpdates = false;

  • Works for me but when a Workflow is awaiting on the task to be completed. We get an error from the Workflow (FormatException) it's trying to convert the String (TaskOutcome) into a Number.
    – Hybris95
    Commented Nov 29, 2016 at 13:45

Answering very late. but following link explains how to approve SharePoint workflow 2013 using c# SSOM


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.