The task
1. Get links to workflow statistics.
2. Get workflow tasks programmatically.
3. Get workflow history programmatically
Solution
1. Links to workflow statistics:
foreach (SPWorkflow wf in list_item.Workflows)
{
string sLink = string.Format("{0}/_layouts/WrkStat.aspx?List={1}&WorkflowInstanceID={2}", web.Url, wf.ListId, wf.InstanceId)
}
web.Url above is the Url property of SPWeb instance.
2. Workflow tasks:
foreach (SPWorkflowTask wt in wf.Tasks)
{
// get any information you like about the wt object, i.e. in this scenario we will output link to the task
string sLink = string.Format("{0}/Lists/{1}/DispForm.aspx?ID={2}", web.Url, SPEncode.UrlEncode(wt.ParentList.Title), wt["ID"])
...
}
3. Workflow history:
Class SPWorkflow has a member HistoryList which represents history list for the workflow.
Let's assume that we are using the SPWorkflow object - wf - from above.
3.1. First we have to make a query to extract history list item related to our workflow instance and list item:
SPQuery queryHistory = new SPQuery();
queryHistory.ViewFields = "<FieldRef Name=\"Description\" /><FieldRef Name=\"Event\" /><FieldRef Name=\"Created\" />";
queryHistory.Query = string.Format("<Where><And><Eq><FieldRef Name=\"WorkflowInstance\" /><Value Type=\"Text\">{0}</Value></Eq><And><Eq><FieldRef Name=\"List\"/><Value Type=\"Text\">{1}</Value></Eq><Eq><FieldRef Name=\"Item\" /><Value Type=\"Integer\">{2}</Value></Eq></And></And></Where>", "{" + wf.InstanceId.ToString() + "}", "{" + list.ID.ToString() + "}", list_item.ID);
3.2. Query history list item and iterate through them:
SPListItemCollection items = wf.HistoryList.GetItems(queryHistory);
foreach (SPListItem item in items)
{
...
}
Enjoy!
1. Get links to workflow statistics.
2. Get workflow tasks programmatically.
3. Get workflow history programmatically
Solution
1. Links to workflow statistics:
foreach (SPWorkflow wf in list_item.Workflows)
{
string sLink = string.Format("{0}/_layouts/WrkStat.aspx?List={1}&WorkflowInstanceID={2}", web.Url, wf.ListId, wf.InstanceId)
}
web.Url above is the Url property of SPWeb instance.
2. Workflow tasks:
foreach (SPWorkflowTask wt in wf.Tasks)
{
// get any information you like about the wt object, i.e. in this scenario we will output link to the task
string sLink = string.Format("{0}/Lists/{1}/DispForm.aspx?ID={2}", web.Url, SPEncode.UrlEncode(wt.ParentList.Title), wt["ID"])
...
}
3. Workflow history:
Class SPWorkflow has a member HistoryList which represents history list for the workflow.
Let's assume that we are using the SPWorkflow object - wf - from above.
3.1. First we have to make a query to extract history list item related to our workflow instance and list item:
SPQuery queryHistory = new SPQuery();
queryHistory.ViewFields = "<FieldRef Name=\"Description\" /><FieldRef Name=\"Event\" /><FieldRef Name=\"Created\" />";
queryHistory.Query = string.Format("<Where><And><Eq><FieldRef Name=\"WorkflowInstance\" /><Value Type=\"Text\">{0}</Value></Eq><And><Eq><FieldRef Name=\"List\"/><Value Type=\"Text\">{1}</Value></Eq><Eq><FieldRef Name=\"Item\" /><Value Type=\"Integer\">{2}</Value></Eq></And></And></Where>", "{" + wf.InstanceId.ToString() + "}", "{" + list.ID.ToString() + "}", list_item.ID);
3.2. Query history list item and iterate through them:
SPListItemCollection items = wf.HistoryList.GetItems(queryHistory);
foreach (SPListItem item in items)
{
...
}
Enjoy!
Comments
Post a Comment