cancel
Showing results for 
Search instead for 
Did you mean: 

Business exception handling in Activiti and Share forms

jservajean
Confirmed Champ
Confirmed Champ
I'm developping custom workflows in Alfresco Share using Activiti.

I was wandering how to handle "business exceptions", that is to say exception raised from the script layer that I want to display nicely in the sahre form to the user.


Let me give you an example :

Let's define a model with mandatory bpm_package association. Now let's say that we want the exact number of documents to be 2.

The first validation is done by the form framework in Share : it displays a "star" on the label of the mandatory field and you can't validate the form until the condition is not fullfilled.

The second validation is more like a "business" validation and is handled in the script associated to a specific event of the task.
For now the only way I found (and use) to raise that kind of exception is to raise an "Error" :

   if ( execution.getVariable("bpm_package").children.length != 2 ){
      throw new Error("You must select exactly 2 documents !");
   }


It is handled by the form runtime by displaying a YUI dialog, but the text is nested into some technical-non-end-user piece of text, like the following :
<em>
org.alfresco.scripts.ScriptException: 00230648 Failed to execute supplied script: 00230647 Error: <strong>You must select exactly 2 documents !</strong> (AlfrescoJS#2)
</em>

I want the message to be "clean" and not to contain the leading "org.alfresco…" and trailing "(AlfrescoJS#2)" texts.

Is there a way :
<ul>
<li>by using a more appriate object to be raised (not Error) and that would be better handled ?</li>
<li>making some kind of tweak in the form definition to handle an Error object ?</li>
</ul>

Thanks for your help.

3 REPLIES 3

afaust
Legendary Innovator
Legendary Innovator
Hello,

as far as I know there is now way for you to pass a clean exception message from a script executed within a workflow to the Share user interface. The problem is that there are many application layers that this exception passes through and every layer usually adds some kind of information to the message whenever it handles an error that is unknown / not specific to that layer. Since the layer that executes scripts does not know (or care) about the specific types of errors any script may throw, it can not know which ones should be passed on unaltered and which need more information - it also does not know or particularily care about the fact that the script is executed within a workflow.
This is one use case where clean isolation of concerns results in situation that may be neither logical nor helpful to the developer / user.

One way I see you can handle this (and other kinds of errors) is by customizing the Alfresco Share JavaScript utility that handles error responses from the submission of the task form, and come up with a way to reliably strip out the unwanted pre-/suffixed information.
Another way would be by implementing your own AlfrescoScriptDelegate / AlfrescoJavaScript utility and handle the Java exception you receive from the script processor yourself, i.e. extracting the original error message and passing that up the stack to the Share user interface.

Regards
Axel

tonyrivet
Champ in-the-making
Champ in-the-making
Did you (or anyone) manage to handle errors on transitions in Share forms ?

The workarounds AFaust suggested could do the trick but is there a "clean" way to do some checks before a transition is processed and return an error message to the user.

jservajean
Confirmed Champ
Confirmed Champ
I think you can throw an error in any of the event thrown by activiti, i.e. before leaving the current task, before creating a new one, on the transition itself (http://docs.alfresco.com/4.1/concepts/wf-process-def-listeners.html).
The handling of the error on the UI side remains to be done, as by default it will be done by a plain YUI dialog…