public static SPListItem WorkflowTaskItemBasedOnListItem(SPWeb web, string listName, string workflowTaskListName, int itemId)
{
SPListItem workflowItem = null;
SPList workflowTasks = web.Lists[workflowTaskListName];
SPList mainList = web.Lists[listName];
SPListItem listItem = mainList.GetItemById(Convert.ToInt32(itemId));
SPWorkflowFilter filter = new SPWorkflowFilter();
filter.InclusiveFilterStates = SPWorkflowState.Running;
// Get a list of workflow tasks associated with current Item
SPWorkflowTaskCollection workTaskColl = web.Site.WorkflowManager.GetItemTasks(listItem, filter);
foreach (SPWorkflowTask task in workTaskColl)
{
if (task != null)
{
workflowItem = workflowTasks.GetItemById(task.ID);
break;
}
}
return workflowItem;
}
This function returns a workflow item based on Parent List item Id. It reads the List Item and finds the associated workflow which are still running against this list item.
Any thoughts on how to go the other direction? i.e. I have the Task item, how do I get it's associated parent List Item?
ReplyDeleteCheck this
ReplyDeletehttp://sansanwal.blogspot.com/2009/08/function-to-read-list-item-id-based-on.html
wow much thanks for help, Sanjay!
ReplyDeleteAndrey Myasnikov
w e b [@] t e g o l a . r u
Will i able to get Attachment file associated to Task , i need to copy this to new task again...
ReplyDeleteOnce you have got an item, you could easily get its attachment, check the sample code-
ReplyDeletepublic static DataTable GetAttachments(string listName, string itemNo)
{
DataTable tb = new DataTable();
using (SPWeb oWeb = WEB_OBJECT)
{
oWeb.AllowUnsafeUpdates = true;
tb.Columns.Add("Name");
tb.Columns.Add("Url");
tb.Columns.Add("SizeKB");
SPFolder folder = null;
try
{
folder = oWeb.Folders[listName];
}
catch
{
folder = oWeb.Folders["Lists"].SubFolders[listName];
}
try
{
folder = folder.SubFolders["Attachments"].SubFolders[itemNo];
foreach (SPFile file in folder.Files)
{
DataRow row = tb.Rows.Add();
row["Name"] = file.Name;
row["Url"] = oWeb.Url + "/" + file.Url;
row["SizeKB"] = ((file.Length / 1024) + 1).ToString() + " KB";
}
}
catch
{
}
oWeb.AllowUnsafeUpdates = false;
}
return tb;
}
Any idea how to retrieve completed workflow related tasks?
ReplyDeleteAny idea how to retrieve tasks for completed workflows?
ReplyDeleteI need to get all runnig tasks and iterate through them to set the outcome to "NotRequired". Any idea?
ReplyDeleteThanks..... It worked....
ReplyDelete