AnsweredAssumed Answered

Property error on JavaScript variables

Question asked by drisschelouati on Oct 20, 2015
Latest reply on Oct 23, 2015 by drisschelouati
Good evening everybody,

I've recently trhown my self in the custom advanced workflows and i now face some problems. First, i have to say that i have been through Jeff Potts excellent  workflow tutorial. I also have to say that every time i do a tutorial like those of Jeff Potts, i prefer using my own set of data, so ireally understand the mechanics, rather than just copying the supplied code.

So i started with the Publish Whitepaper workflow and transformed it into "Review Strategy Paper". The differences are simple (prefix "scwf" becomes "adwf"), the Marketing and Operations groups are replaced with mine : Strategy and Finance groups. I also chose (since it is not a feature that is stable at the moment) to remove the Third party approval and to replace it with an additional review step for Directors group (please look at the screenshot for the workflow Diagram).

Everything is ok with spring beans, messages, share congiguration and is packaged in two AMP (one for repo and one for share). Alfresco succeeds at deploying the workflow and i can see it in the workflow list. When i start this "StrategyReview" workflow, it is submited fine, but the issue occurs when the strategy party or the finance party wants to approve the review step:



org.activiti.engine.ActivitiException: Exception while invoking TaskListener: Exception while invoking TaskListener: 09200041 Failed to execute supplied script: 09200040 ReferenceError: "adwf_approveCount" n'est pas défini (AlfrescoJS#2)



meaning that "adwf_approveCount" isnt defined. According to Jeff's instructions, i defined it in the process definition. The reject action works with the first group to accomplish the task. But when the second group tries to accomplish its task, either by approving (reproduces the same issue as above) or by rejecting the step, the following issue occurs:



org.activiti.engine.ActivitiException: Unknown property used in expression: ${adwf_approveCount < 2}




Here is the process definition:




<?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="StrategyReview" name="Strategy Document Review" isExecutable="true">
    <startEvent id="startevent1" name="Start" activiti:formKey="adwf:submitReviewTask"></startEvent>
    <scriptTask id="submit" name="submit" scriptFormat="javascript" activiti:autoStoreVariables="false">
         <script><![CDATA[var adwf_approveCount = 0;]]></script>
    </scriptTask>
    <parallelGateway id="parallelgateway1" name="Parallel Gateway"></parallelGateway>
    <userTask id="strategyReview" name="Strategy Review" activiti:candidateGroups="GROUP_Strategy" activiti:formKey="adwf:activitistrategyReview">
    <extensionElements>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
            <activiti:field name="script">
                <activiti:string>
                    if(task.getVariableLocal('adwf_approveRejectOutcome') == 'Approve') {
                        var newApprovedCount = adwf_approveCount + 1;
                        execution.setVariable('adwf_approveCount', newApprovedCount);
                    }
                </activiti:string>
            </activiti:field>
        </activiti:taskListener>
    </extensionElements>
    </userTask>
    <userTask id="financeReview" name="Finance Review" activiti:candidateGroups="GROUP_Finance" activiti:formKey="adwf:activitifinanceReview">
    <extensionElements>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
            <activiti:field name="script">
                <activiti:string>
                    if(task.getVariableLocal('adwf_approveRejectOutcome') == 'Approve') {
                        var newApprovedCount = adwf_approveCount + 1;
                        execution.setVariable('adwf_approveCount', newApprovedCount);
                    }
                </activiti:string>
            </activiti:field>
        </activiti:taskListener>
    </extensionElements>
    </userTask>
<userTask id="revise" name="Revise" activiti:assignee="${initiator.properties.userName}" activiti:formKey="adwf:activitiRevise">
    <extensionElements>
<activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
        <activiti:field name="script">
            <activiti:string>if(task.getVariableLocal('adwf_reviseOutcome') == 'Re-submit') {
                execution.setVariable('adwf_resubmit', true);
                } else {
                execution.setVariable('adwf_resubmit', false);
                }
            </activiti:string>
        </activiti:field>
    </activiti:taskListener>
</extensionElements>
    </userTask>
    <parallelGateway id="parallelgateway2" name="Parallel Gateway"></parallelGateway>
    <userTask id="directorReview" name="Director Review" activiti:candidateGroups="GROUP_Directors" activiti:formKey="adwf:activitidirectorReview">
    <extensionElements>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
            <activiti:field name="script">
                <activiti:string>
                    if(task.getVariableLocal('adwf_approveRejectOutcome') == 'Approve') {
                        var newApprovedCount = adwf_approveCount + 1;
                        execution.setVariable('adwf_approveCount', newApprovedCount);
                    }
                </activiti:string>
            </activiti:field>
        </activiti:taskListener>
    </extensionElements>
    </userTask>
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
    <exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway"></exclusiveGateway>
    <userTask id="ApprovedNotification" name="Approved Notification" activiti:assignee="${initiator.properties.userName}" activiti:formKey="adwf:activitiApprovedNotification"></userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="startFlow" sourceRef="startevent1" targetRef="submit"></sequenceFlow>
    <sequenceFlow id="submitFlow" sourceRef="submit" targetRef="parallelgateway1"></sequenceFlow>
    <sequenceFlow id="strategyInputFlow" sourceRef="parallelgateway1" targetRef="strategyReview"></sequenceFlow>
    <sequenceFlow id="financeInputFlow" sourceRef="parallelgateway1" targetRef="financeReview"></sequenceFlow>
    <sequenceFlow id="strategyOutputFlow" sourceRef="strategyReview" targetRef="parallelgateway2"></sequenceFlow>
    <sequenceFlow id="financeOutputFlow" sourceRef="financeReview" targetRef="parallelgateway2"></sequenceFlow>
    <sequenceFlow id="firstDecisionFlow" sourceRef="parallelgateway2" targetRef="exclusivegateway1"></sequenceFlow>
    <sequenceFlow id="firstReviseFlow" sourceRef="exclusivegateway1" targetRef="revise">
         <conditionExpression xsi:type="tFormalExpression"><![CDATA[${adwf_approveCount < 2}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="directorInputFlow" sourceRef="exclusivegateway1" targetRef="directorReview">
         <conditionExpression xsi:type="tFormalExpression"><![CDATA[${adwf_approveCount == 2}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="directorOutputFlow" sourceRef="directorReview" targetRef="exclusivegateway2"></sequenceFlow>
    <sequenceFlow id="approveFlow" sourceRef="exclusivegateway2" targetRef="ApprovedNotification">
         <conditionExpression xsi:type="tFormalExpression"><![CDATA[${adwf_approveCount == 3}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="secReviseFlow" sourceRef="exclusivegateway2" targetRef="revise">
         <conditionExpression xsi:type="tFormalExpression"><![CDATA[${adwf_approveCount < 3}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="endFlow" sourceRef="ApprovedNotification" targetRef="endevent1"></sequenceFlow>
    <sequenceFlow id="resubmitFlow" sourceRef="revise" targetRef="submit">
         <conditionExpression xsi:type="tFormalExpression"><![CDATA[${adwf_resubmit == true}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="abortReviseFlow" sourceRef="revise" targetRef="endevent1">
          <conditionExpression xsi:type="tFormalExpression"><![CDATA[${adwf_resubmit == false}]]></conditionExpression>
    </sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_StrategyReview">
    <bpmndi:BPMNPlane bpmnElement="StrategyReview" id="BPMNPlane_StrategyReview">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="10.0" y="180.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="submit" id="BPMNShape_submit">
        <omgdc:Bounds height="55.0" width="105.0" x="80.0" y="170.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="parallelgateway1" id="BPMNShape_parallelgateway1">
        <omgdc:Bounds height="40.0" width="40.0" x="220.0" y="177.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="strategyReview" id="BPMNShape_strategyReview">
        <omgdc:Bounds height="55.0" width="105.0" x="280.0" y="116.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="financeReview" id="BPMNShape_financeReview">
        <omgdc:Bounds height="55.0" width="105.0" x="280.0" y="217.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="revise" id="BPMNShape_revise">
        <omgdc:Bounds height="55.0" width="105.0" x="280.0" y="310.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="parallelgateway2" id="BPMNShape_parallelgateway2">
        <omgdc:Bounds height="40.0" width="40.0" x="400.0" y="177.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="directorReview" id="BPMNShape_directorReview">
        <omgdc:Bounds height="55.0" width="105.0" x="550.0" y="170.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
        <omgdc:Bounds height="40.0" width="40.0" x="480.0" y="177.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusivegateway2" id="BPMNShape_exclusivegateway2">
        <omgdc:Bounds height="40.0" width="40.0" x="680.0" y="177.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="ApprovedNotification" id="BPMNShape_ApprovedNotification">
        <omgdc:Bounds height="55.0" width="105.0" x="740.0" y="170.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="910.0" y="180.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="startFlow" id="BPMNEdge_startFlow">
        <omgdi:waypoint x="45.0" y="197.0"></omgdi:waypoint>
        <omgdi:waypoint x="80.0" y="197.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="submitFlow" id="BPMNEdge_submitFlow">
        <omgdi:waypoint x="185.0" y="197.0"></omgdi:waypoint>
        <omgdi:waypoint x="220.0" y="197.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="strategyInputFlow" id="BPMNEdge_strategyInputFlow">
        <omgdi:waypoint x="240.0" y="177.0"></omgdi:waypoint>
        <omgdi:waypoint x="240.0" y="143.0"></omgdi:waypoint>
        <omgdi:waypoint x="280.0" y="143.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="financeInputFlow" id="BPMNEdge_financeInputFlow">
        <omgdi:waypoint x="240.0" y="217.0"></omgdi:waypoint>
        <omgdi:waypoint x="240.0" y="244.0"></omgdi:waypoint>
        <omgdi:waypoint x="280.0" y="244.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="strategyOutputFlow" id="BPMNEdge_strategyOutputFlow">
        <omgdi:waypoint x="385.0" y="143.0"></omgdi:waypoint>
        <omgdi:waypoint x="420.0" y="143.0"></omgdi:waypoint>
        <omgdi:waypoint x="420.0" y="177.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="financeOutputFlow" id="BPMNEdge_financeOutputFlow">
        <omgdi:waypoint x="385.0" y="244.0"></omgdi:waypoint>
        <omgdi:waypoint x="420.0" y="244.0"></omgdi:waypoint>
        <omgdi:waypoint x="420.0" y="217.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="firstDecisionFlow" id="BPMNEdge_firstDecisionFlow">
        <omgdi:waypoint x="440.0" y="197.0"></omgdi:waypoint>
        <omgdi:waypoint x="480.0" y="197.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="firstReviseFlow" id="BPMNEdge_firstReviseFlow">
        <omgdi:waypoint x="500.0" y="217.0"></omgdi:waypoint>
        <omgdi:waypoint x="483.0" y="337.0"></omgdi:waypoint>
        <omgdi:waypoint x="385.0" y="337.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="directorInputFlow" id="BPMNEdge_directorInputFlow">
        <omgdi:waypoint x="520.0" y="197.0"></omgdi:waypoint>
        <omgdi:waypoint x="550.0" y="197.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="directorOutputFlow" id="BPMNEdge_directorOutputFlow">
        <omgdi:waypoint x="655.0" y="197.0"></omgdi:waypoint>
        <omgdi:waypoint x="680.0" y="197.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="approveFlow" id="BPMNEdge_approveFlow">
        <omgdi:waypoint x="720.0" y="197.0"></omgdi:waypoint>
        <omgdi:waypoint x="740.0" y="197.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="secReviseFlow" id="BPMNEdge_secReviseFlow">
        <omgdi:waypoint x="700.0" y="217.0"></omgdi:waypoint>
        <omgdi:waypoint x="430.0" y="443.0"></omgdi:waypoint>
        <omgdi:waypoint x="332.0" y="365.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="endFlow" id="BPMNEdge_endFlow">
        <omgdi:waypoint x="845.0" y="197.0"></omgdi:waypoint>
        <omgdi:waypoint x="910.0" y="197.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="resubmitFlow" id="BPMNEdge_resubmitFlow">
        <omgdi:waypoint x="280.0" y="337.0"></omgdi:waypoint>
        <omgdi:waypoint x="132.0" y="337.0"></omgdi:waypoint>
        <omgdi:waypoint x="132.0" y="225.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="abortReviseFlow" id="BPMNEdge_abortReviseFlow">
        <omgdi:waypoint x="332.0" y="365.0"></omgdi:waypoint>
        <omgdi:waypoint x="692.0" y="401.0"></omgdi:waypoint>
        <omgdi:waypoint x="927.0" y="215.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>





Here is also the task model file :



<?xml version="1.0" encoding="UTF-8"?>
<!– Definition of new Model –>
<model name="adwf:workflowmodel"
    xmlns="http://www.alfresco.org/model/dictionary/1.0">

    <!– Optional meta-data about the model –>
    <description>AD Workflow Demo</description>
    <author>Driss Chelouati</author>
    <version>1.0</version>

    <!– Imports are required to allow references to definitions in other models –>
    <imports>
        <import uri="http://www.alfresco.org/model/dictionary/1.0"
            prefix="d" />
        <import uri="http://www.alfresco.org/model/bpm/1.0"
            prefix="bpm" />
    </imports>

    <!– Introduction of new namespaces defined by this model –>
    <namespaces>
        <namespace uri="http://www.ad.com/model/workflow/1.0"
            prefix="adwf" />
    </namespaces>

    <types>
       
<type name="adwf:submitReviewTask">
    <parent>bpm:startTask</parent>
</type>

<type name="adwf:activitistrategyReview">
    <parent>adwf:activitiReviewTask</parent>
</type>

<type name="adwf:activitifinanceReview">
    <parent>adwf:activitiReviewTask</parent>
</type>

<type name="adwf:activitidirectorReview">
    <parent>adwf:activitiReviewTask</parent>
</type>

<type name="adwf:activitirevise">
    <parent>bpm:activitiOutcomeTask</parent>
    <properties>
        <property name="adwf:reviseOutcome">
            <type>d:text</type>
            <default>Abort</default>
            <constraints>
                <constraint type="LIST">
                    <parameter name="allowedValues">
                        <list>
                            <value>Re-submit</value>
                            <value>Abort</value>
                        </list>
                    </parameter>
                </constraint>
            </constraints>
        </property>
    </properties>
   
    <overrides>
        <property name="bpm:packageItemActionGroup">
        <default>edit_package_item_actions</default>
        </property>
        <property name="bpm:outcomePropertyName">
        <default>{http://www.ad.com/model/workflow/1.0}reviseOutcome</default>
        </property>
    </overrides>
   
</type>

<type name="adwf:activitiReviewTask">
    <parent>bpm:activitiOutcomeTask</parent>
    <properties>
        <property name="adwf:approveRejectOutcome">
            <type>d:text</type>
            <default>Reject</default>
            <constraints>
                <constraint type="LIST">
                    <parameter name="allowedValues">
                        <list>
                            <value>Approve</value>
                            <value>Reject</value>
                        </list>
                    </parameter>
                </constraint>
            </constraints>
        </property>
    </properties>
   
    <overrides>
        <property name="bpm:packageItemActionGroup">
            <default>read_package_item_actions</default>
        </property>
        <property name="bpm:outcomePropertyName">
            <default>{http://www.ad.com/model/workflow/1.0}approveRejectOutcome</default>
        </property>
    </overrides>
   
</type>

<type name="adwf:activitiApprovedNotification">
    <parent>bpm:workflowTask</parent>
    <overrides>
        <property name="bpm:packageItemActionGroup">
            <default>read_package_item_actions</default>
        </property>
    </overrides>
</type>
       
    </types>

</model>



Iam new to JavaScript language (and all programming stuff), so please dont blame me if i got wrong on something obvious :) ! Iam really interested in becoming better with activiti embedded in Alfresco and handling the Alfresco JavaScript API. Thanks for your help!

Attachments

Outcomes