Update a SharePoint Workflow Task

Posted on August 4, 2009. Filed under: Code Snippets | Tags: , , |

private void updateTaskItem(SPWorkflowTaskProperties tProperties)
            //Pull out the Task Items from the tasks list by passing
            //a query as variable to SPListItemCollection GetItems()
            Guid tListID = new Guid(workflowProperties.TaskListId.ToString());
            SPQuery tQuery = new SPQuery();
            //Query to pull the list item from the Tasks list. Items with Status ‘Completed’ will be left out.
            tQuery.Query = “<Where><Neq><FieldRef Name=’Status’/>” + “<Value Type=’CHOICE’>Completed</Value></Neq></Where>”;
                //Pull out the Tasks List using the ID provided in workflow properties
                SPList tasksList = workflowProperties.Web.Lists[tListID];
                //Querying the Tasks List returns a set of Tasks, store them.
                SPListItemCollection tCollection = tasksList.GetItems(tQuery);

                //Parse through each of the Task Item
                foreach (SPListItem tListItem in tCollection)
                    //Condition Execution, Verify for the Right Task and modify the Status
                    if (tListItem.Title == tProperties.Title)
                        if (tListItem[“Status”] == “Not Started”)
                            tListItem[“Status”] = “Completed”;



Call this method by providing the respective Taskproperties in your MOSS Workflow to modify the status or any other field.


Make a Comment

Leave a Reply

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

WordPress.com Logo

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


    Xperiments n Xperiences. For the Last 5 years I have been providing variuos portal solutions (SharePoint focused) to my clients and now I intend to publish few of those solutions 'Not As It Is', which might help you. – Mash


    Subscribe Via RSS

    • Subscribe with Bloglines
    • Add your feed to Newsburst from CNET News.com
    • Subscribe in Google Reader
    • Add to My Yahoo!
    • Subscribe in NewsGator Online
    • The latest comments to all posts in RSS


Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: