K2[blackpearl] introduces the new concept of Actions and Outcomes. Anytime a Client Event is used, the process designer is provided the ability to create a list of possible choices for the people actioning this task. This list is called 'Actions'.
Additionally, K2[blackpearl] depricates the K2.net 2003 K2ROM object model. It is now replaced with the WorkflowClient (Namespace: SourceCode.Workflow.Client / File: C:\Program Files\K2 blackpearl\SourceCode.Workflow.Client.dll)
Please note, if you are familiar with the older K2ROM object model, you will feel very comfortable with the new one.
Below (and attached) is an ASP.NET code sample for how to programmatically interact with the actions to first populate a drop down list and then get the selected value and set the specific action within the WorkflowClient API.
Please note, you will need to add a reference to the SourceCode.Workflow.Client.dll within the project.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SourceCode.Workflow.Client;
public partial class _Default : System.Web.UI.Page
{
private string m_strBPServer = "blackpearl";
private int m_nBPPort = 5252;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string strSN = string.Empty;
// get the serial number from the query string
if (Request["SN"] != null)
{
strSN = Request["SN"];
}
if (strSN != String.Empty)
{
// open a K2 connection
SourceCode.Workflow.Client.Connection oConn = new SourceCode.Workflow.Client.Connection();
oConn.Open(m_strBPServer);
// get this specific task
SourceCode.Workflow.Client.WorklistItem oWli = oConn.OpenWorklistItem(strSN);
if (oWli != null)
{
// retrieve properties
lblProcess.Text = oWli.ProcessInstance.Name;
lblActivity.Text = oWli.ActivityInstanceDestination.Name;
lblFolio.Text = oWli.ProcessInstance.Folio;
// *** POPULATE THE DROPDOWNLIST WITH THE ACTIONS ***
foreach (Action oAct in oWli.Actions)
{
ddlActions.Items.Add(oAct.Name);
}
}
// close the connection
oConn.Close();
}
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string strSN = string.Empty;
// get the serial number
if (Request["SN"] != null)
{
strSN = Request["SN"];
}
if (strSN != String.Empty)
{
// open a K2 connection
SourceCode.Workflow.Client.Connection oConn = new SourceCode.Workflow.Client.Connection();
oConn.Open(m_strBPServer);
// get the worklist item
SourceCode.Workflow.Client.WorklistItem oWli = oConn.OpenWorklistItem(strSN);
if (oWli != null)
{
// *** SET THE APPROPRIATE ACTION AS SELECTED WITHIN THE COLLECTION ***
foreach (Action oAct in oWli.Actions)
{
if (oAct.Name == ddlActions.SelectedItem.Text)
{
oAct.Execute();
break;
}
}
}
// *** NO NEED TO CALL THE FINISH() METHOD WHEN ACTIONS ARE USE ***
// *** LIKE WE USED TO WITH K2.NET 2003 K2ROM ***
// oWli.Finish();
// close the connection
oConn.Close();
btnSubmit.Enabled = false;
}
}
}
The statements and opinions made in my postings are my own, and do not reflect the opinions of SourceCode Technology Holdings, Inc. or its subsidiaries. All information is provided as is with no warranties, express or implied, and grants no rights or licenses.