An Avanade Blogging Community

Welcome to An Avanade Blogging Community Sign in | Join | Help
in Search

John Reynolds' Tech Blog

Programmatically complete Sharepoint out of box Approval Workflow

I have not seen anyone else on the web do this, and I spent a couple days trying to figure this out.
Given an out of box Sharepoint Approval workflow, I wanted to be able to update the Approval task programmatically, and have the status update to Approved or Rejected as appropriate.
Simple, right? Not so much. You can't update the task directly, and there is no documentation to speak of on the workflow.
I compared the extended properties of an approved & rejected task and found out that the internals of the workflow use the following symbols to represent the Approved and Rejected state:
Approved = "#"
Rejected = "@"

Makes perfect sense!!!! Good grief...

Anyway, here's what you really want: the code.

SPListItem task = pendingItem.Tasks[1]; // Modify this code to get the most recent task in case an item is edited

Hashtable data = new Hashtable();

            data["Comments"] = "whoop de do";

            data["PercentComplete"] = 1.0f;

            data["Completed"] = "TRUE";

            data["Status"] = "Completed";

// Use one or the other

            data["TaskStatus"] = "@";   // Rejected

            data["TaskStatus"] = "#";   // Approved

SPWorkflowTask.AlterTask(task, data, true);

Published Monday, November 03, 2008 2:13 PM by johnrey

Comments

 

sudhir.kesharwani said:

hey good stuff,  i found a lot of internal stuff are not documented anywhere for sharepoint,

all of us has to spend a lot of time figuring out how microsoft handles the situation.
November 3, 2008 11:11 PM
 

sudhir.kesharwani said:

hey good stuff,  i found a lot of internal stuff are not documented anywhere for sharepoint,

all of us has to spend a lot of time figuring out how microsoft handles the situation.
November 3, 2008 11:11 PM
 

sudhir.kesharwani said:

hey good stuff,  i found a lot of internal stuff are not documented anywhere for sharepoint,

all of us has to spend a lot of time figuring out how microsoft handles the situation.
November 3, 2008 11:11 PM
 

sudhir.kesharwani said:

hey good stuff,  i found a lot of internal stuff are not documented anywhere for sharepoint,

all of us has to spend a lot of time figuring out how microsoft handles the situation.
November 3, 2008 11:11 PM
Anonymous comments are disabled

This Blog

Post Calendar

<November 2008>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

Post Categories

Syndication