cancel
Showing results for 
Search instead for 
Did you mean: 

throw new Error in Alfresco workflow

irenailievska
Champ on-the-rise
Champ on-the-rise
I want to throw error in a custom alfreso workflow, but just as a popup message to the user that he entered something wrong.
I tried to do this

<activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[
            …………………….
            var message = 'IT LIVES';
            throw message;]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>


I tried doing this also



throw new Error("some text");



Since I am writing here it means it didn't work.
Please can somebody help me?
Just a simple alert window doesn't help me if the user submits the action after all. I need something to stop the user from continuing the process if the data he entered is not correct.

Thanks in advance,
Irena
19 REPLIES 19

I tried the same thing. I don't know what is wrong. The error that I get is shown on the error.png file that I attached. I don't know. Maybe I need to set something somewhere?
This is very important for my project and I am stuck with this Smiley Sad.
Thank you people for trying to help Smiley Happy
Irena

Hi Irena,

Please attach your bpm file so we can plug it into our environment to debug for you.

I just removed the throw error part. You can try to put it any where. Can you just tell me if I am supposed to set it somewhere else so I can throw an error? Maybe in some file…
Thank you

Hi,
I'm able to see the error message.Refer the attached.

irenailievska
Champ on-the-rise
Champ on-the-rise
But that error is not what I need. I need to have the message (ex."The values you entered are not correct") in the popup instead of the generic code.
This is the problem I have Smiley Happy

muralidharand
Star Contributor
Star Contributor
Here I'm throwing error message as "called", you can change this message as per you wish.

<activiti:string><![CDATA[throw new Error ("called");]]></activiti:string>

to


<activiti:string><![CDATA[throw new Error ("The values you entered are not correct");]]></activiti:string>

Please let me know, If I understood your question wrongly.

Thanks Smiley Happy. I would have to manage like this…. I thought that I might be able to have only the message I want instead of org.activiti.engine.ActivitiException: Exception while invoking TaskListener: Exception while invoking TaskListener: 01010014 Failed to execute supplied script: 01010013 Error: The values you entered are not correct .
But I will do it like this.
Thank you and all the others that helped Smiley Very Happy

Sadly,you can't get rid out of alfresco / activiti namespace.

I have one more issue - I use the way you suggested and it works, but I need to check if a checkbox is checked or not.
So when at the beginning the box is not checked it throws the error as it should, but if I check it after the throwing of the error it still throws the error - like it can't catch the change I made.
Is there some way to catch the change I made?
Thank you Smiley Happy

************* EDIT ****************
I found my error - I was checking if the checkbox value was true or false but with 'true' and needed to exclude the single quotes. Smiley Happy

krutik_jayswal
Elite Collaborator
Elite Collaborator

When alfresco is rendering the workflow form , it is rendering the transition button using the activiti-transition.js file.Basically this buttons are doing nothing more but submitting the workflow form.

This is how the flow is going when we submit a workflow form.

  1. activiti-transition is submiting the workflow form.
  2. Using a function named as submitForm which resides inside alfresco.js, it is invoking an submit event of form
  3. Inside the forms-runtime.js file there is one function named as _submitInvoked(handles the submit event of form), which is responsible for making an ajax call and submitting the workflow form.If there is error while submitting , it will display the error which is from backend.

So the best to customize the error pop up is to change activiti-transition.ftl and activiti-transition.js file , to make an ajax call and handle the response as we want.

activiti-transition.js  file has a function named as onClick: function ActivitiTransitions_onClick(e, p_obj).What it does is , it converts the form element in json object and finally submit that form.Below is line which is responsible for this.

Alfresco.util.submitForm(p_obj.getForm());

Inside this activiti-transition.js  file if we do all this things manually and handle the server response, we will be able to handle the error message ultimately.