Sample code how to retrieve worklist item in K2 BlackPearl using Folio in WorkflowCriteria.
using System;
using System.Collections.Generic;
using System.Text;
using SourceCode.Hosting.Client;
using SourceCode.Workflow.Client;
namespace K2Samples
{
public class WorkflowAccessingSample
{
public void RetrieveWorklistOpenItemBasedOnFolio()
{
// TODO: Replace these placeholder values with values for your environment
Worklist worklist = null;
WorklistItem worklistitem = null;
string _serverName = "blackpearl";
string _user = "K2Student";
string _domain = "DENALLIX";
string _password = "K2pass!";
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 = 5252;
connectionString.UserID = _user;
connectionString.WindowsDomain = _domain;
connectionString.Password = _password;
connectionString.SecurityLabelName = "K2"; //the default label
// open a K2 connection
Connection connection = new Connection();
connection.Open(_serverName, connectionString.ToString());
try
{
WorklistCriteria wc = new WorklistCriteria();
wc.AddFilterField(WCField.ProcessFolio, WCCompare.Equal, "NR - 1");
// open the worklist item
worklist = connection.OpenWorklist(wc);
if (worklist.Count == 0)
{
Console.WriteLine("There has been a problem retrieving the K2 process
data. Please ensure that the account has rights to the K2
BlackPearl Workflow Item and that you are connecting to the
BlackPearl server.");
}
else
{
worklistitem = worklist[0];
// retrieve properties of worklist item
Console.WriteLine("Process Instance Name: " +
worklistitem.ProcessInstance.Name);
Console.WriteLine("Process Destination: " +
worklistitem.ActivityInstanceDestination.Name);
Console.WriteLine("Process Folio: " +
worklistitem.ProcessInstance.Folio);
// get the workflow actions
string workflowActions = "Workflow Actions: ";
foreach (Action action in worklistitem.Actions)
{
workflowActions += Environment.NewLine + action.Name;
}
// write actions to console
Console.WriteLine(workflowActions + Environment.NewLine);
Console.ReadLine();
}
}
catch (Exception ex)
{
// write error to console
Console.WriteLine("Error: " + ex.Message);
Console.ReadLine();
}
finally
{
// close the connection
connection.Close();
}
}
}
}