Opening delegated worklist items or managed user worklist items
When you need to open a Worklist Item from a subordinate's task list, or open a Worklist Item that was delegated to the currently-connected user, you need to use specific methods to open that worklist item.
These code snippets require references to the assemblies:
- SourceCode.HostClientAPI
- SourceCode.Workflow.Client
Opening a Managed User's WorklistItem
Managers can open worklist items from their subordinates' tasks list with the OpenManagedWorklistItem method, as shown below. This assumes that the currently-connected user is defined as the manager of the managed user in the underlying User Identity store.
Opening a Managed User's WorklistItem
using(SourceCode.Workflow.Client.Connection K2Conn = new Connection()) {
//open a simple connection for simplicity
K2Conn.Open("localhost");
//get the task serial number from somewhere (e.g. query string or worklist)
string serialNumber = "[ProcessInstanceId_ActivityInstanceDestinationId]";
//if you want to open a worklist item from a managed user's (i.e. subordinate's) tasklist
//use the OpenManagedWorklistItem method as pass the managed user's username
WorklistItem K2WListItemManagedUser = K2Conn.OpenManagedWorklistItem("[managedUserUsername]", serialNumber);
}
Opening a Delegated WorklistItem (including Out of Office items)
When a Worklist Items has been delegated (either through Out of Office or manually delegated), use the OpenSharedWorklistItem method to open the shared worklist item, as shown below. Pass an empty string value for the ManagedUser parameter. The SharedUser field is used for accessing the shared worklist item.
Opening a Delegated WorklistItem (including Out of Office items)
using(SourceCode.Workflow.Client.Connection K2Conn = new Connection()) {
//open a simple connection for simplicity
K2Conn.Open("localhost");
//get the task serial number from somewhere (e.g. query string or worklist)
string serialNumber = "[ProcessInstanceId_ActivityInstanceDestinationId]";
//if you are opening another user's worklist item that was
//manually delegated to the current account, or
//delegated with Out of Office,
//use the OpenSharedWorklistItem method and pass the original user's username
//leaving the managed user value empty
//if you do not know the original user name, you can obtain it by
//retrieving the task using the worklist and querying the AllocatedUser property
//string originalUser = K2WLItem.AllocatedUser;
WorklistItem K2WListItemDelegated = K2Conn.OpenSharedWorklistItem("[originalUserName]", string.Empty, serialNumber);
}
Opening a Delegated WorklistItem for a Managed User
A user's manager may also have access to a shared worklist item that was delegated to the managed user, in which case the ManagedUser and SharedUser fields must be populated when calling the OpenSharedWorklistItem method.
Opening a Delegated WorklistItem for a Managed User
using(SourceCode.Workflow.Client.Connection K2Conn = new Connection()) {
//open a simple connection for simplicity
K2Conn.Open("localhost");
//get the task serial number from somewhere (e.g. query string or worklist)
string serialNumber = "[ProcessInstanceId_ActivityInstanceDestinationId]";
//if you are opening another user's worklist item that was delegated to the current account
//or delegated with Out of Office and also uses the managed user value
//use the OpenSharedWorklistItem method and pass the original user's username
//as well as managed user
//if you do not know the original user name, you can obtain it by
//retrieving the task using the worklist and querying the AllocatedUser property
//string originalUser = K2WLItem.AllocatedUser;
WorklistItem K2WListItemDelegatedManagedUser = K2Conn.OpenSharedWorklistItem("[originalUserName]", "[managedUserUsername]", serialNumber);
}