A team mate of mine was stuck with a curious issue. She was using SharePoint’s in-built Approval workflow but was using a custom ASP.net application to talk to a custom webservice hosted inside SharePoint server. That particular web service was having a method to complete the Approval workflow’s task using SPWorkflowTask.AlterTask method.
Here is the code snippet that was being used to update the task from within the web method.
Now no matter how it was being updated, the workflow task was being updated but the workflow itself was stuck in “In Progress” state and never completes.
This was a curious thing as I had earlier also worked with similar issue but with a custom workflow created for SharePoint using Visual Studio. I had a sample code which was working with it and the customer workflow was getting completed.
Now what was different here?
After some troubleshooting and debugging, found that Approval workflow requires a property “TaskStatus” to be set in the hashtable being passed to SPWorkflowTask.AlterTask method. The valid values for “TaskStatus” property are:
ht["TaskStatus"] = "#"; // This would mean that the task has been Approved
ht["TaskStatus"] = "@"; // This would mean that the task has been Rejected
So finally the code in the web method was updated to update the TaskStatus property as below:
After this update, the tasks where updated properly and workflow completes as expected.
As always… Happy Coding