How to access and return information from the Global Worklist
In this example, the global worklist that is available in the Workspace Management Console is accessed. A serial number from a user's worklist item is matched against two values from a specific worklist item. Some data about that item is written to the console.
The Worklist sample code is written for use with Web based forms. Sample code for Windows based forms will be available in a future release of the Developer's Reference
In this example you are using the SourceCode.Workflow.Management namespace instead of the SourceCode.Workflow.Client namespace. See the topic How to retrieve the worklist of a user and open a worklist item for more information on opening a user's worklist.
The main object of the SourceCode.Workflow.Management namespace is the WorkflowManagementServer, which allows many administrative tasks to be performed once the object is created and a connection is made to the K2 server. In the example below GetWorklistItems retrieves a collection of worklist items that match what is available under the Workflow Server > Worklists node in the Management Console.
You must have Administrative rights on the K2 workflow server in order to access the global worklist.
In the following example, provide values for the variables that begin with the underscore (_) character to match your environment and scenario. If pasting this code into a console application, set values for the variables and paste the code into a class called from the Main function.
References to SourceCode.HostClientAPI and SourceCode.Workflow.Management are also required.
using System; using System.Collections.Generic; using System.Text; using SourceCode.Hosting.Client; using SourceCode.Workflow.Management; namespace K2Samples { class WorkflowAcessingSample { public void RetrieveGlobalWorklist() { // TODO: Replace these placeholder values with values for your environment string _serial = "10_13"; SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder connectionString = new SourceCode.Hosting.Client.BaseAPI.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()); // parse serial number to get procInstID and actInstDestID string procInst = _serial.Substring(0,_serial.IndexOf("_")); string actInstDest = _serial.Substring(_serial.IndexOf("_")+1); // loop through each worklist item foreach (WorklistItem worklistItem in workflowServer.GetWorklistItems("", "", "", "", "", "", "")) { if (worklistItem.ProcInstID.ToString() == procInst && worklistItem.ActInstDestID.ToString() == actInstDest) { 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()); } } Console.ReadLine(); } catch (Exception ex) { // write error to console Console.WriteLine("Error: " + ex.Message); Console.ReadLine(); } finally { // close the connection workflowServer.Connection.Close(); } } } }