Start a workflow (from non-Microsoft external system)

A project I was working on last year had an interesting requirement relating to K2.NET 2003.  Rather than using Sharepoint as the launcher for a workflow, instead, their main line-of-business system would be commencing workflows, upon submission of a web-based form (request).

This was an Oracle Forms / JAVA based solution – but thanks to the K2ROM (Runtime Object Model), we were able to expose the workflow to be launch’able from the Oracle application.

As part of the proof-of-concept, we use a JavaScript function in a HTML page – with the calling “stub” to be integrated to Oracle Forms.

In a nutshell, the process to initiate the K2.NET workflow was from within an ASP.NET Web Service (asmx).   

The following code (VB.NET) is all it takes !    Explanation & further comments below :

<WebMethod()> _
Public Sub StartWorkflow(ByVal vintRefID As Integer)

      Dim connK2 As New K2ROM.Connection
      connK2.Open(AppSettings.Get("MyK2Server"))
      Dim procK2 As K2ROM.ProcessInstance
      procK2 = connK2.CreateProcessInstance(AppSettings.Get("CustWF"))
      procK2.DataFields("RefId").Value = vintRefID
      procK2.Folio = "Customer Ref : " & vintRefID
      connK2.StartProcessInstance(procK2, False)
connK2.Close()
End Sub

Here’s a breakdown of the above code listing :

(1) Create an object reference to be used for connection the K2ROM server 
      Dim connK2 As New K2ROM.Connection

(2) Open the connection, using a setting from WEB.CONFIG
      connK2.Open(AppSettings.Get("MyK2Server"))

(3) Create a process instance, using named process from WEB.CONFIG file
      Dim procK2 As K2ROM.ProcessInstance
      procK2 = connK2.CreateProcessInstance(AppSettings.Get("CustWF"))

(4) Set the data fields within the workflow – ie. initialisation / kick-off values
      procK2.DataFields("RefId").Value = vintRefID
      procK2.Folio = "Customer Ref : " & vintRefID

(5) Start the process – c’mon – get going !!      FALSE – to specifiy if process to be started asynchronously
      connK2.StartProcessInstance(procK2, False)

(6) IMPORTANT – close the connection to the K2.NET server
      connK2.Close()

That’s as easy as it gets.  This demonstrates the use of a config file to determine the location of the K2.NET server, as well as the K2.NET process name.   The following was the WEB.CONFIG file used (snippet) :

<appSettings>
  <add key="MyK2Server" value="DEVK2NETSRV"/>
  <add key="CustWF" value="PURCH\CUSTORD"/>
</appSettings>

Advertisements
This entry was posted in K2.net 2003 (SP4). Bookmark the permalink.

3 Responses to Start a workflow (from non-Microsoft external system)

  1. Peter Yao says:

    What is the typical integration model to pass Windows Authentication token from non-MS system to web service so that the request can be logged under the real initiator?

  2. Chris says:

    In the situation described, the “system” was the initiator (public facing user), and so the web-service would run using the credentials required within K2.NET – and would have permissions to start process.

    If it was a “person”, and needing to retain the initator name – would probably have to pass a user account “string” to the web service.

    And then – within the web service, impersonate the user when connecting to K2.NET.

  3. Peter Yao says:

    Assuming we are not asking user for their password, we would not be able to impersonate the user connecting to K2 .NET?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s