How to programatically determine what user(s) opened a Worklist Item for a currently active client event instance
For an activity that is “Plan just once” (default) that has multiple destination users assigned there there is only one slot created. As expected, on one of the users opens the worklist item, it appears as “Open” for that user, and “Allocated” for the other destination users. Sometimes it can be useful to present in a custom application which user opened the task.
This can be accomplished via the SourceCode.Workflow.Management API. Below is a sample method that will recover the user based upon some basic information:
private string GetUsersThatOpenedAWorklistItem(int nProcInstID,
string strFullProcessName, // "Project Name\ProcessName"
string strActivityName,
string strFolio)
{
string strUsers = string.Empty;
// WorkflowManagement required a connection to be made by a properly authorized K2 Server Admin account.
// Refer to the K2 Developers Reference for details on how to format a connection string
SourceCode.Workflow.Management.WorkflowManagementServer oServer = new SourceCode.Workflow.Management.WorkflowManagementServer("localhost", 5555);
oServer.Open();
// retrieve a list of worklist items
SourceCode.Workflow.Management.WorklistItems oItems = oServer.GetWorklistItems(String.Empty,
strFullProcessName,
strActivityName,
String.Empty,
strFolio,
String.Empty,
String.Empty);
// iterate the list
foreach (SourceCode.Workflow.Management.WorklistItem oItem in oItems)
{
// make sure we are working with the exact proc inst in case the Folio is not unique
if (nProcInstID == oItem.ProcInstID)
{
// the person the opened the task will have a status of OPEN. other dest users will have "ALLOCATED"
if(oItem.Status == SourceCode.Workflow.Management.WorklistItem.WorklistStatus.Open)
{
// now grab the user name from the Actioner object
if (strUsers != string.Empty)
{
strUsers += ",";
}
else
{
strUsers += oItem.Actioner.Name;
}
}
}
}
// close the connection
oServer.Connection.Close();
return strUsers;
}