Skip to main content

how do you force an event into error with K2 studio

I suppose it depends on your needs.  I have done this two different ways.

 

1) Use a DataEvent for force a divide by 0 error.  

Just configure an expression to compute 1/0 and assign it to a process or activity field.  This forces the activity into an error state.  Of course, there is no recovery from this... you cannot simply select 'retry' under Error Profiles.  The only recovery method is to use 'Goto Activity' from the Management Console to force the workflow to start some other activity.

 

2)  Use some .Net code to throw an exception conditionally

Here, I built a small .Net DLL with a single static method.  I pass in some data and based on that data the code choses whether or not an exception is needed.  If so, it throws an exception.  This DLL is then exposed to K2 as a SmartObject via Endpoints Assembly which I can easily call from workflow.  The advantage to this is that it allows me an easier recovery path.  I can retry the activity which re-calls the .Net DLL which, assuming we no longer meet the conditions for throwing the exception, will exit normally allowing the workflow to continue.

 

I used this second method when calling a web service.  The web servie returned a success/failure value and possibly an error message.  My DLL checks the success/failure flag and if it was a failure, sends an email then throws the exception.  This gives me early notification of a problem rather than having people monitor K2's error profiles screen.  Later, the activity could be retried and if the web service returns success, my DLL realizes that and doesn't bother sending emails or throwing an exception. 

 


Reply