Comleting or Stopping a process


Badge +3

Hi


In my parent process I have an IPC event that calls multiple instances of a child process.


Each child gets approval for individual lines of a purchase order.


The parent process waits for all the child processes to complete before moving on UNLESS the child process is rejected. If it is rejected then the parent moves on, rejects the PO and comlpletes.


The problem is that when a line is rejected the parent completes but the other incomplete child processes remain active and the users can still go and approve or reject them.


Is there a way to stop/complete all other active child processes as soon as one is rejected?


Any help much appreciated


Rich


4 replies

Badge +8
Hey Rich.
I have implemented same scenario, here's the details.

All the sub process(which needs to be stopped), should have a activity with some server event after the start process. That means your process would take a parallel path as soon as it starts.

One path which is your usual stuff, second path just have one activity with server events, server events are
1. Load SN (Server Event):
K2.ProcessInstance.DataFields["YourDataField"].Value = K2.SerialNumber;
Load the data field, save this value, we will use this value to finish this process

2.Smart object event (Smart object) :
I use this event to save the above datafield in smar object, so i would have all the child processes serial number saved against parent id.
I would use parent id to query all the child processes sn to stop them.

3. wait for notification (Server event)
K2.Synchronous = false;
this would make the server event to wait, that means this process would not finish untill you use code to stop this server event.

So if your sub process take a happy path, last activity of sub process should stop the server event in that sub process otherwise your process would not stop


What this would do is that, once you start the process your server event would be executed as expected but it would not finish. We need to finish this activity through code.

So, let you process take a happy path, which is usual path and let your server event wait for you to finish it. In the last activity of sub process, use the serial number of server event we saved to stop the server event

ServerItem Item;
Item = Conn.OpenServerItem(SN);
Item.Finish();

Need to stop all the processes.
You have the server event saved for all the child processes, against parent id in smart object. Query them and use the code below.

ServerItem Item;
Item = Conn.OpenServerItem(SN);
Item.Finish();

HTH, let me know if you any more questions
16208iB93F71BD93FA2BB3.bmp
Badge +11

This is a very common pattern and I think K2.netdeveloper's approach is a good one.  I use something very similar when the originator must be able to cancel the workflow at any point and there are IPC processes.  Here's another option you might wish to investigate:


http://k2underground.com/forums/post/23472.aspx


David

Badge +3

Hi NetDev


I have done something very similar to what you have done but now need to kill off the processes and can't get it working.


The serial number for the process is stored in a data field called SerialNo and I have tried to use the following code to kill off the process:


ServerItem Item;


Item = Conn.OpenServerItem(K2.ProcessInstance.DataFields["SerialNo"].Value);


Item.Finish();


However when I try to build with this I get 2 errors which are:



  1. Type or namespace name 'ServerItem' could not be found
  2. The name 'Conn' does not exist in the current context

What namespace do the ServerItem and Conn objects belong in?


 

Badge +8
This code is to be used in aspx pages

using SourceCode.Workflow.Client;


Connection Conn = new Connection();
Conn.Open(ServerName);
ServerItem Item2;
Item2 = Conn.OpenServerItem(ServerItemSerialNumber);
Item2.Finish();

well, you would use this code in aspx pages, on button click event. When user wants to kill all the processes, you would execute this code. That is the reason i save all the serveritemserial numbers against a processid in smart object.
Once all the processes for a parent process "A" needs to be killed, execute a load method in smart object with porcessid as input parameter and fetch all the sub/child processes serial numbers and then execute the code above



HTH

Reply