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

Copy

Retrieve the global worklist example

//TODO: build a connection string with the SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder
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;

    //get the global worklist. You can pass values as method parameters to filter the items returned
    worklistItems = workflowServer.GetWorklistItems("", "", "", "", "", "", "");

    //you can also create criteria to filter the global worklist
    SourceCode.Workflow.Management.Criteria.WorklistCriteriaFilter critFilter = new SourceCode.Workflow.Management.Criteria.WorklistCriteriaFilter();
    //filter for specific workflow definition
    critFilter.AddRegularFilter(SourceCode.Workflow.Management.WorklistFields.ProcessFullName, SourceCode.Workflow.Management.Criteria.Comparison.Equals, @"[project]\[workflowname]");
    //filter for a specific folio
    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());
        // serial number is ProcInstID + "_" + ActInstDestID
        Console.WriteLine("ProcInstID: " + worklistItem.ProcInstID.ToString());
        Console.WriteLine("ActInstDestID: " + worklistItem.ActInstDestID.ToString());
        //if the destination is role, iterate over members of the role
        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) {
    //do something with the error
} finally {
    //always close the connection
    workflowServer.Connection.Close();
}