How to use server event code do external call

  • 29 November 2008
  • 1 reply
  • 1 view

Badge +2

Hi


       Now I have database backend is sqlserver 2005 (not database of blackpearl) and some activity in workflow want to check something in the database backend such as : check field finished = true .  When the K2 know status finished equal true then goto next activity.


        And Now I write .Net Trigger to check and hook it to database finished My sample code


Imports System.Data


Imports System.Data.SqlClient


Imports Microsoft.SqlServer.Server


Partial Public Class MyFirstClrTrigger


'<Microsoft.SqlServer.Server.SqlTrigger("FOR INSERT", "checkUserRole", "UserTable")>


<Microsoft.SqlServer.Server.SqlTrigger(Event:="FOR INSERT", Name:="checkUserRole", target:="UserTable")> _


Public Shared Sub checkUserRole()


Dim triggContext As SqlTriggerContext = SqlContext.TriggerContext()


Dim userType As String = String.Empty


If triggContext.TriggerAction = TriggerAction.Insert Then


Using connection As New SqlConnection("context connection=true")


connection.Open()


Dim sqlComm As New SqlCommand


Dim sqlPipe As SqlPipe = SqlContext.Pipe()


sqlComm.Connection = connection


sqlComm.CommandText = "SELECT Type from INSERTED"


userType = sqlComm.ExecuteScalar.ToString()


If userType.ToUpper = "ADMIN" Then


sqlPipe.Send("Hello !!! You have the Admin role.")


sqlPipe.Send("We can use e-mail codes here to inform.")


Else


End If


End Using


End If


End Sub


End Class


  And I want to Know:


          - How to use server event code to call external source (such as .net trigger) and pass instance Id also.


          - How I can use .net trigger call back process in K2


thanks


1 reply

Badge +6

Hi,

long reply needed for that one... but for now I can give you some steps.

  1. you need to reference your external DLL at the process level (right icon above the design canvas). After that, you can access the methods of your external DLL into a "K2 server event".
  2. Add a server event, and put him asynchronous (K2.synchronous=false)
  3. Add your .net code to call your External method and pass the event instance ID (a serial number) to your external environment.
  4. In your external environnement, add K2 code to "finish" the server event with the serial number you have.

I don't have all your business needs but maybe, you don't need to use an external call and you can do directly your SQL command into the K2 server event ? Also, have you explored the use of a SmartObject with an SQL Service Object to achieve the smae thing?

HTH

 

Reply