AnsweredAssumed Answered

Activiti custom workflow error on run + Alfresco 4

Question asked by msyepez on Nov 14, 2011
Latest reply on Nov 22, 2012 by ivanatap
Hello everyone. I've been fiddling with Activiti Designer for quite a bit, and even though I struggled deploying a custom workflow, everything seems to be fine now. Turns out I modified a workflow template (Parallel Review And Approve Activiti Process), so that when the workflow chooses the "reject" flow, an AlfrescoMailTask is run after the user reject task. That's the only change I made.

I deployed the bpmn20.xml file in \tomcat\webapps\alfresco\WEB-INF\classes\alfresco\workflow, and added the workflow definition on \tomcat\webapps\alfresco\WEB-INF\classes\alfresco\bootstrap-context.xml. The workflow appears now on the drop down list Share offers on starting a workflow; however, when I go through the reject path, this message appears when attempting to hit Next after the reject task:

org.activiti.engine.ActivitiException: Exception while invoking TaskListener: Exception while invoking TaskListener: 10140016 Failed to execute supplied script: missing } in compound statement (AlfrescoJS#6)

This is the bpmn20 xml:

<?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: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://activiti.org/bpmn20">
  <process id="EniProcess" name="Revisión / aprobación con correo Eni-Alfresco">
    <extensionElements>
      <activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
        <activiti:field name="script">
          <activiti:string>execution.setVariable('wf_approveCount', 0);
execution.setVariable('wf_actualPercent', 0);
execution.setVariable('wf_reviewerCount', bpm_assignees.size());</activiti:string>
        </activiti:field>
      </activiti:executionListener>
    </extensionElements>
    <startEvent id="start" name="Start" activiti:formKey="wf:submitParallelReviewTask"></startEvent>
    <userTask id="reviewTask" name="Revisión" activiti:assignee="${reviewAssignee.properties.userName}" activiti:formKey="wf:activitiReviewTask">
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>if (typeof bpm_workflowDueDate != 'undefined') task.setVariableLocal('bpm_dueDate', bpm_workflowDueDate);</activiti:string>
          </activiti:field>
        </activiti:taskListener>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>if(task.getVariableLocal('wf_reviewOutcome') == 'Approve') {
var newApprovedCount = wf_approveCount + 1;
var newApprovedPercentage = (newApprovedCount / wf_reviewerCount) * 100;

execution.setVariable('wf_approveCount', newApprovedCount);
execution.setVariable('wf_actualPercent', newApprovedPercentage);</activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
      <multiInstanceLoopCharacteristics isSequential="false">
        <loopDataInputRef>bpm_assignees</loopDataInputRef>
        <inputDataItem name="reviewAssignee"></inputDataItem>
        <completionCondition>${wf_actualPercent &gt;= wf_requiredApprovePercent}</completionCondition>
      </multiInstanceLoopCharacteristics>
    </userTask>
    <exclusiveGateway id="reviewDecision" name="Review Decision"></exclusiveGateway>
    <userTask id="approved" name="Documento aprobado" activiti:assignee="${initiator.properties.userName}" activiti:formKey="wf:approvedParallelTask">
      <documentation>
                The document was reviewed and approved.
            </documentation>
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>if (typeof bpm_workflowDueDate != 'undefined') task.setVariableLocal('bpm_dueDate', bpm_workflowDueDate);
if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;

// Set parallel review params on task, to be kept in history
task.setVariableLocal('wf_reviewerCount', wf_reviewerCount);
task.setVariableLocal('wf_requiredPercent', wf_requiredPercent);
task.setVariableLocal('wf_actualPercent', wf_actualPercent);</activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    <userTask id="rejected" name="Documento rechazado" activiti:assignee="${initiator.properties.userName}" activiti:formKey="wf:rejectedParallelTask">
      <documentation>
                The document was reviewed and rejected.
            </documentation>
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>if (typeof bpm_workflowDueDate != 'undefined') task.setVariableLocal('bpm_dueDate', bpm_workflowDueDate);
if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;

// Set parallel review params on task, to be kept in history
task.setVariableLocal('wf_reviewerCount', wf_reviewerCount);
task.setVariableLocal('wf_requiredPercent', wf_requiredPercent);
task.setVariableLocal('wf_actualPercent', wf_actualPercent);</activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    <endEvent id="end" name="End"></endEvent>
    <sequenceFlow id="flow1" name="" sourceRef="start" targetRef="reviewTask"></sequenceFlow>
    <sequenceFlow id="flow2" name="" sourceRef="reviewTask" targetRef="reviewDecision"></sequenceFlow>
    <sequenceFlow id="flow3" name="" sourceRef="reviewDecision" targetRef="approved">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${wf_actualPercent >= wf_requiredApprovePercent}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow4" name="" sourceRef="reviewDecision" targetRef="rejected"></sequenceFlow>
    <sequenceFlow id="flow5" name="" sourceRef="approved" targetRef="end"></sequenceFlow>
    <serviceTask id="alfrescoMailtask1" name="Alfresco Mail Task" activiti:class="org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate">
      <extensionElements>
        <activiti:field name="script">
          <activiti:string>var mail = actions.create("mail");
mail.execute(bpm_package);
</activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <sequenceFlow id="flow6" name="" sourceRef="rejected" targetRef="alfrescoMailtask1"></sequenceFlow>
    <sequenceFlow id="flow7" name="" sourceRef="alfrescoMailtask1" targetRef="end"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_EniProcess">
    <bpmndi:BPMNPlane bpmnElement="EniProcess" id="BPMNPlane_EniProcess">
      <bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
        <omgdc:Bounds height="35" width="35" x="30" y="200"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="reviewTask" id="BPMNShape_reviewTask">
        <omgdc:Bounds height="55" width="105" x="105" y="190"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="reviewDecision" id="BPMNShape_reviewDecision">
        <omgdc:Bounds height="40" width="40" x="250" y="197"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="approved" id="BPMNShape_approved">
        <omgdc:Bounds height="55" width="105" x="218" y="60"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="rejected" id="BPMNShape_rejected">
        <omgdc:Bounds height="55" width="105" x="218" y="320"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="end" id="BPMNShape_end">
        <omgdc:Bounds height="35" width="35" x="475" y="207"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="alfrescoMailtask1" id="BPMNShape_alfrescoMailtask1">
        <omgdc:Bounds height="55" width="105" x="440" y="320"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="65" y="217"></omgdi:waypoint>
        <omgdi:waypoint x="105" y="217"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="210" y="217"></omgdi:waypoint>
        <omgdi:waypoint x="250" y="217"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="270" y="197"></omgdi:waypoint>
        <omgdi:waypoint x="270" y="164"></omgdi:waypoint>
        <omgdi:waypoint x="270" y="115"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="270" y="237"></omgdi:waypoint>
        <omgdi:waypoint x="270" y="284"></omgdi:waypoint>
        <omgdi:waypoint x="270" y="320"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="323" y="87"></omgdi:waypoint>
        <omgdi:waypoint x="492" y="87"></omgdi:waypoint>
        <omgdi:waypoint x="492" y="207"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
        <omgdi:waypoint x="323" y="347"></omgdi:waypoint>
        <omgdi:waypoint x="440" y="347"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
        <omgdi:waypoint x="492" y="320"></omgdi:waypoint>
        <omgdi:waypoint x="492" y="242"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

Besides that, I'm not sure I understand how to use models… What's their purpose?  :oops:

Outcomes