Working with the management (global) Worklist
This example shows how to retrieve the global worklist (this is the worklist that is available in the K2 administration tools, If you want to build a K2 task list for users, see the topic Retrieving the worklist for information on opening a user's worklist).
You must have Administrative rights on the K2 workflow server in order to access the global worklist.
This sample code requires references to the assemblies:
- SourceCode.HostClientAPI
- SourceCode.Workflow.Management
SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder connectionString = new SCConnectionStringBuilder();
connectionString.Authenticate = true;
connectionString.Host = "localhost";
connectionString.Integrated = true;
connectionString.IsPrimaryLogin = true;
connectionString.Port = 5555;
WorkflowManagementServer workflowServer = new WorkflowManagementServer();
try {
workflowServer.CreateConnection();
workflowServer.Connection.Open(connectionString.ToString());
WorklistItems worklistItems = null;
worklistItems = workflowServer.GetWorklistItems("", "", "", "", "", "", "");
SourceCode.Workflow.Management.Criteria.WorklistCriteriaFilter critFilter = new SourceCode.Workflow.Management.Criteria.WorklistCriteriaFilter();
critFilter.AddRegularFilter(SourceCode.Workflow.Management.WorklistFields.ProcessFullName, SourceCode.Workflow.Management.Criteria.Comparison.Equals, @ "[project]\[workflowname]");
critFilter.AddRegularFilter(SourceCode.Workflow.Management.WorklistFields.Folio, SourceCode.Workflow.Management.Criteria.Comparison.Equals, "[folio]");
worklistItems = workflowServer.GetWorklistItems(critFilter);
foreach(WorklistItem worklistItem in worklistItems) {
Console.WriteLine("Process Name: " + worklistItem.ProcName.ToString());
Console.WriteLine("Start Date: " + worklistItem.StartDate.ToString());
Console.WriteLine("ProcInstID: " + worklistItem.ProcInstID.ToString());
Console.WriteLine("ActInstDestID: " + worklistItem.ActInstDestID.ToString());
if (worklistItem.Actioner.ActionerType == SourceCode.Workflow.Management.ActionerType.Role) {
foreach(SourceCode.Workflow.Management.WorklistUser destUser in worklistItem.Users) {
Console.WriteLine("Status: " + destUser.Status);
}
}
}
} catch (Exception ex) {
} finally {
workflowServer.Connection.Close();
}