AnsweredAssumed Answered

Business exception handling in Activiti and Share forms

Question asked by jservajean on Jan 23, 2014
Latest reply on Jun 30, 2014 by jservajean
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 :
org.alfresco.scripts.ScriptException: 00230648 Failed to execute supplied script: 00230647 Error: <strong>You must select exactly 2 documents !</strong> (AlfrescoJS#2)

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

Is there a way :
<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>

Thanks for your help.