How to programmatically get/set K2[blackpearl] Actions from ASP.NET

Last post 08-31-2007, 10:27 PM by k2eric. 2 replies.
Sort Posts: Previous Next
  •  08-21-2007, 9:55 PM 17930

    How to programmatically get/set K2[blackpearl] Actions from ASP.NET

    Attachment: ExampleWebApp.zip

    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.
  •  08-23-2007, 6:07 PM 18017 in reply to 17930

    • Koos is not online. Last active: 04-30-2008, 1:32 AM Koos
    • Top 500 Contributor
    • Joined on 06-04-2007
    • Redmond, Washington, USA
    • Posts 9
    • Points 24

    Re: How to programmatically get/set K2[blackpearl] Actions from ASP.NET

    FYI - with K2 [BlackPearl] we decided to make the client API completely Action based. therefore "update" and "finish" no longer exists in the client API.

     When building the solution, use Actions as explained by Bob (above) to iterate, display and execute actions. The action will dictate behaviour (goto, release , sleep, update, finish)

     for example to create a PO approval process where certain users are allowed to "approve" while others are only allowed to provide feedback (update).   You would create 2 actions "Approve" and "Update" and assign rights to destinations accordingly.

  •  08-31-2007, 10:27 PM 18327 in reply to 18017

    Re: How to programmatically get/set K2[blackpearl] Actions from ASP.NET

    Here is an alternate way to bind the actions to a dropdown list instead of looping through the actions and adding them to the dropdownlist :

     DropDownList1.DataSource = wli.Actions;
      DropDownList1.DataValueField = "Name";
      DropDownList1.DataTextField = "Name";
      DropDownList1.DataBind();

     


    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.
View as RSS news feed in XML