Encapsulating Code to Use in K2 Process Activity

  • 15 July 2008
  • 1 reply
  • 0 views

Badge +1

What approach to you use to encapsulate custom code so that it can be used in multiple server and exception event handlers?


For example, code to do an LDAP lookup that is used in multiple activities server events in a single K2 process. Copy and paste reuse at the moment.


Do you create a custom .NET library or K2 service? 


 


1 reply

Badge +9

You are correct in that your choices are a custom .NET assembly or a K2 Service Broker.


A .NET assembly can be referenced in the process.  You will then need to "View Code" on any entity in which you wish to use this assembly and then you'll need to write the actual code. 


A service broker will allow you to create a SmartObject(s) to interact with this functionality.  You can interact with this SmartObject via the SmartObject event as well as dragging over in things like Line Rules and input properties in other wizards.  You can then also use this SmartObject in things like ASP.net and InfoPath forms as well as the K2 Report Designer.  The main benefit of this approach is that once the service is created, there is no coding within the process definition itself to interact with.  Additionally this promotes easy reuse of this functionality throughout K2 processes, smartobjects and UIs.


So, I would suggest that if this functionality you are referring to is only going to be used in a couple of locations in a single process, then a .NET assembly is probably suffecient.  However if it will be more than that, I'd recommend going the Service Broker/SmartObject approach for the reasons stated above.  FYI, there is a new blackmarket project released this week, the Dynamic Assembly Service (http://www.k2underground.com/k2/ProjectHome.aspx?ProjectID=67), which may interest you.  It is a service broker that is freely available that will expose any static methods in a .NET assembly as a K2 Service from which you can base a SmartObject from.  So, all you would need to do is write your desired code as a static method in a .NET assembly and then use this servicebroker to expose it to K2.


HTH.

Reply