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

muralidharand
Star Contributor
Star Contributor
ScriptTaskListener code runs in Server and not in the browser side.
So, if you call
 alert('welcome'); 
will not show.

OK it makes sense… I know that the code runs on server side, just wanted to try anything. Do you perhaps know how to throw an error message (popup) ?

Hi,

Use the method in this way and it should work:
throw(message)
that will throw a popup on your screen.

Exception while invoking TaskListener: 00150013 Failed to execute supplied script ….
It looks like that throw expects to get something else. I tried adding message as you suggested but it doesn't work.
I am putting this code inside the workflow definition. Maybe I am supposed to put it somewhere else?

muralidharand
Star Contributor
Star Contributor
Hi,

You have to use
 throw new Error("") 
to error message to the user.
Here is the code snippet to throw error message to user.


<serviceTask id="alfrescoScripttask1" name="Validate input params" activiti:class="org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate">
      <extensionElements>
        <activiti:field name="script">
          <activiti:string>
        <![CDATA[if (bpm_package.children.length == 0 )
        {
          throw new Error ("No workflow folder found.Please select one.");
        }
        if (bpm_package.children.length > 1 )
        {
          throw new Error ("More than one workflow attachments found, Please select only one workflow folder.");
        }
]]></activiti:string>
        </activiti:field>
      </extensionElements>
</serviceTask>



Hope this helps you.

Thanks,
Murali.

Does it have to be a service task in order to throw new Error? I tried doing the same thing, but in an User Task.
I need to throw the error when the user makes a choice in the workflow - when he completes a task. This is so in order to not let the user task to continue if the info entered is wrong. So I tried throwing error in the complete event of the user task.
Is this possible?

Hi,

I use it with a user task, though as a supplied script. I write a separate script and embed it to the user task, that way I do not have to redeploy the bpm every time I make changes.
Try using the "throw" in a independent script.

I tested with simple user task and it is working me, means throwing the error message.
If you use the service task, it is failed, I believe , the current task will not be completed and goes back to prev. task. I am not sure what happen if you update some values in the system.



<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="myDemoProcess" name="My Demo Process" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="User Task" activiti:assignee="admin">
      <extensionElements>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[throw new Error ("called");]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_myDemoProcess">
    <bpmndi:BPMNPlane bpmnElement="myDemoProcess" id="BPMNPlane_myDemoProcess">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="210.0" y="200.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55.0" width="105.0" x="290.0" y="190.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="440.0" y="200.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="245.0" y="217.0"></omgdi:waypoint>
        <omgdi:waypoint x="290.0" y="217.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="395.0" y="217.0"></omgdi:waypoint>
        <omgdi:waypoint x="440.0" y="217.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>


muralidharand
Star Contributor
Star Contributor
I haven't tried at the user task completion. Anyway, let me take a look and will come back to you.