in

James Mann's Blog

Get the item a SharePoint workflow task is associated with

This is handy. SharePoint helpfully populates the meta data with the GUID of the list and the ID of the item a WF instance is associated with. These are stored in "ows_WorkflowListId" and "ows_WorkflowItemId" fields on the task list item.

 An example of using this is from an InfoPath form in the form load code behind.

SPListItem currentListItem = SPContext.Current.ListItem;
if (currentListItem != null)
{
  object associatedWfListId = currentListItem["ows_WorkflowListId"];
  object associatedWfItemId = currentListItem["ows_WorkflowItemId"];
 
  if (associatedWfItemId != null && associatedWfListId != null)
  {
    SPListItem item = web.Lists.GetList(new Guid(associatedWfListId.ToString()), false).GetItemById(int.Parse(associatedWfItemId.ToString()));
    // THE ABOVE ITEM IS THE ASSOCIATED LIST ITEM
  }
}
Published Mar 10 2008, 01:24 PM by James
Filed under: , ,

Comments

 

Mustafa Refai said:

It is really good blog!

March 25, 2008 9:14 PM
 

Satish said:

Thanks.. Helped me today.

September 10, 2008 10:14 PM
 

Martin Cohen said:

This is very helpful, but you made a small mistake.  Your last statement returns a SPList object.  Once you have the list, you can use associatedWFItemId to get the item from the list.

November 13, 2008 7:42 PM
 

Martin Cohen said:

I withdraw my last comment.  For some reason, the full last statement is not showing up in my browser.  When I did a copy and paste, I got the full statement, which is correct.  Please accept my apology.

November 13, 2008 7:46 PM
 

taskworkflow said:

Nice blog !

Good job, Thanks for the information

December 25, 2008 8:35 AM
 

Joseph said:

Thank you for the code . It was really helpful for me.  

February 16, 2009 9:48 AM
 

Robert Graauw said:

Awesome.

thnx dude

September 10, 2009 4:26 PM

Leave a Comment

(required)  
(optional)
(required)  
Add
Black Marble 2004-2010
Powered by Community Server (Commercial Edition), by Telligent Systems