Retrieving the worklist
A common requirement is to create a customized K2 worklist or to retrieve all tasks for a user. The OpenWorklist method is the most-commonly used approach to retrieve tasks for a particular user. The OpenWorklist method returns a Worklist object, which contains a collection of WorklistItem.
The code snippet below shows how to connect to a K2 server and retrieve the worklist items for the connected user. It then loops through each worklist item and reads some data about the item.
This sample code requires references to the assemblies:
- SourceCode.HostClientAPI
- SourceCode.Workflow.Client
Retrieve the worklist items
using (SourceCode.Workflow.Client.Connection K2Conn = new Connection()) {
//open a simple connection for simplicity
K2Conn.Open("localhost");
//retrieve the entire worklist for the connected user
SourceCode.Workflow.Client.Worklist K2WList = K2Conn.OpenWorklist();
//iterate over the worklist items in the worklist
foreach(SourceCode.Workflow.Client.WorklistItem K2WLItem in K2WList) {
//do something with the worklist item
//you can query properties/objects contained in the worklist item object
string serialNumber = K2WLItem.SerialNumber;
string status = K2WLItem.Status.ToString();
string Folio = K2WLItem.ProcessInstance.Folio;
}
}