Finishing an Asynchronous Server Event


Badge +9

Hi All,


Consider the following scenario :


I have a process. The process has an activity that has an async server event.


The process is triggered from a windows appl . I want to finish the Server Event . How do I do it ?


 


10 replies

Badge +8

Hi,


When the Asyn Server Event becomes active, the K2 server generates an Event Serial number for it at runtime. The only way to finish the server event is with this serial number, so you have to save it somewhere where the calling application which is supposed to finish the server event can get hold of it.


Then in the calling application you use the K2ROM to open and finish the server event as follows:


//Serial Number is typically saved in a table when the Server Event becomes Active
String mySerialNo = “K2ProdServer,34,77";
SourceCode.K2ROM.Connection myConnection = new SourceCode.K2ROM.Connection();
myConnection.Open("yourServerName");
SourceCode.K2ROM.ServerItem myServerItem;
myServerItem = myConnection.OpenServerItem(mySerialNo) ;
myServerItem.Finish();


 

Badge +9

Hi smiddie,


Thanks a lot for replying.


My only doubt is how do I capture the serial number. In Ur example, U have hardcoded the Serial Number (String mySerialNo = “K2ProdServer,34,77"; )


 But how do I know the serial number for that particular Server Event.


As  per my knowledge, Serial Number is a property of "ServerItem" class as well as of "WorkListItem"  class in K2ROM namespace. My only concern is to capture the Serial Number of that particular Server Event.


 Pls guide .


 Thanks and Regards

Badge +11

Hi Sourcecode,


In the code behind the server event itself, a 'ServerEventContext' object is passed in as a parameter to the Main function.  You can obtain the serial number of the event from this object and save it to a file or database table - for your external application to pick up.


HTH,


Ockert

Badge +9

Hi Ockert,


Thanks a lot for replying.


In which table is the Serial Number stored ?


Thanks and Regards

Badge +9

A K2 Serial Number is a dynamically generated value.  I don't believe it is actually stored within a specific field, by itself, within the K2 database.


When Ockert mentions it can be retrieved from within the server event and saved off to a database for later reuse by external application, he is referring to retrieving the serial number from within the code context of a K2 Server Event (i.e. from within K2 Studio). 


For example:


public void Main(ServerEventContext K2)
{
 string strSerialNumber = K2.SerialNumber;


 // now do something with the serial number like save it to a DB
 
}


The database Ockert refers to is not a K2 database but a custom, external datastore (say a SQL table you create in your own database) that this server event can populate, with any necessary supporting data and the external application can query to find the appropiate serial number.

Badge +9

Hi Bob,


Thanks a lot for replying.


In K2 Help file, it is mentioned that


"The SerialNumber gets generated by K2.net 2003 Server during execution of a Process Instance. The SerialNumber is a combination of [K2Server,ProcessInstanceID,EventInstanceID] making each SerialNumber unique on the K2.net 2003 Server. "


And I do believe that ProcessInstanceID and EventInstanceID will be getting stored in K2 Database. That is why I asked about the table.


Also is it true that for a particular Server Item , for the Serial Number which is generated , only ProcessInstanceID changes.


EventInstanceID remains constant.


Thanks and Regards

Badge +9

The process instance ID would remain the same throughout the life of a specific instance of the workflow.  I believe the EventInstanceID would change for every event instance within a process instance. 


 

Badge +9

Hi Bob,


Thanks a lot for replying.


Yesterday I was testing this thing. I found that everytime a process is trigerred viz., a new instance is created, then ProcessInstanceID changes but EventInstanceID remains constant. Because of the fact that ServerName is also constant,  so a unique Serial Number is generated.


Pls clarify.


Thanks and Regards

Badge +9

Hi Bob,


Here I would like to discuss something. If an activity has an async server event and the process instance completes, then why do we need to explictly finish the Server Event through it's Serial Number ?


Thanks and Regards

Badge +11

Hi Sourcecode,


First, an async server event is similar to a client event - stopping the process instance at that point waiting for user input.  The only difference is that an async server event expects 'machine' input instead of user input.  In other words, it is a way of stopping the process flow and wait for an external application to finish the server event before it can continue.


If your process completed before your async server event has been finished, you must have had some other process branch or logical routing to enable the process instance to complete.  Normally, a process instance will not complete unless the async server event has been explicitly finished.  If the process instance has completed, the server event will obviously not exist any more.


From within the server event you need to store the serial number of the event to an external (your own) database or file - for your application to pick it up from there (as Bob explained).


True, under normal conditions, the eventinstid should stay the same and the process instance id will change for each new process instance created.  This is however not guaranteed at all and you should NOT rely on the assumption that the eventinstid will remain the same across new instances.


HTH,


Ockert

Reply