如何正确声明,更改和使用工作流程变量?

时间:2017-02-15 03:24:39

标签: javascript workflow alfresco alfresco-share activiti

根据波茨先生亲切提供的example,我已经制定了合同批准制度。

BPMN表示法中的业务流程如下所示。

Activiti Eclipse BPMN 2.0 Designer

enter image description here

Alfresco正在运行的业务流程方案:

enter image description here

为了创建活动图,我使用了Activiti Eclipse BPMN 2.0 Designer 5.18。以下是此插件生成的过程的说明:

<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="contractsApproval" name="Contracts Approval" isExecutable="true">
    <startEvent id="startevent1" name="Start" activiti:formKey="scwf:submitReviewTask"></startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <userTask id="usertask1" name="Approval of the first group" activiti:candidateGroups="GROUP_First" activiti:formKey="scwf:activitiFirstReview">
      <extensionElements>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[if(task.getVariableLocal('scwf_approveRejectOutcome') == 'Approve') {
                            var newApprovedCount = scwf_approveCount + 1;
                            execution.setVariable('scwf_approveCount', newApprovedCount);
                        }]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    <userTask id="usertask3" name="Revise" activiti:assignee="${initiator.properties.userName}" activiti:formKey="scwf:activitiRevise">
      <extensionElements>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[if(task.getVariableLocal('scwf_reviseOutcome') == 'Re-submit') {
                    execution.setVariable('scwf_resubmit', true);
                    } else {
                    execution.setVariable('scwf_resubmit', false);
                    }]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    <userTask id="usertask4" name="Approval of the second group" activiti:candidateGroups="GROUP_Second" activiti:formKey="scwf:activitiSecondReview">
      <extensionElements>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[if(task.getVariableLocal('scwf_approveRejectOutcome') == 'Approve') {
                            var newApprovedCount = scwf_approveCount + 1;
                            execution.setVariable('scwf_approveCount', newApprovedCount);
                        }
        ]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    <serviceTask id="scripttask1" name="Send a document for approval" activiti:class="org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate">
      <extensionElements>
        <activiti:field name="runAs">
          <activiti:string><![CDATA[admin]]></activiti:string>
        </activiti:field>
        <activiti:field name="script">
          <activiti:string><![CDATA[execution.setVariable('scwf_approveCount', 0);
            execution.setVariable('scwf_tpApproved', false);]]></activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <parallelGateway id="parallelgateway1" name="Parallel Gateway"></parallelGateway>
    <parallelGateway id="parallelgateway2" name="Parallel Gateway"></parallelGateway>
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="scripttask1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="scripttask1" targetRef="parallelgateway1"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="parallelgateway1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow4" sourceRef="parallelgateway1" targetRef="usertask4"></sequenceFlow>
    <sequenceFlow id="flow5" sourceRef="usertask1" targetRef="parallelgateway2"></sequenceFlow>
    <sequenceFlow id="flow6" sourceRef="usertask4" targetRef="parallelgateway2"></sequenceFlow>
    <sequenceFlow id="flow7" sourceRef="parallelgateway2" targetRef="exclusivegateway1"></sequenceFlow>
    <sequenceFlow id="flow9" sourceRef="exclusivegateway1" targetRef="usertask3">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${scwf_approveCount < 2}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow13" sourceRef="usertask3" targetRef="scripttask1">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${scwf_resubmit == true}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="usertask5" name="Approved Notification" activiti:assignee="${initiator.properties.userName}" activiti:formKey="scwf:activitiApprovedNotification">
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[var setWebFlagAction = actions.create("set-web-flag");
                        setWebFlagAction.parameters["active"] = true;
                        for (var i = 0; i < bpm_package.children.length; i++) {
                            logger.log("Approving node:" + bpm_package.children[i].nodeRef);
                            setWebFlagAction.execute(bpm_package.children[i]);
                        }]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    <sequenceFlow id="flow15" sourceRef="usertask5" targetRef="endevent1"></sequenceFlow>
    <sequenceFlow id="flow16" sourceRef="usertask3" targetRef="endevent1">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${scwf_resubmit == false}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow17" sourceRef="exclusivegateway1" targetRef="usertask5"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_contractsApproval">
    <bpmndi:BPMNPlane bpmnElement="contractsApproval" id="BPMNPlane_contractsApproval">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="0.0" y="163.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="790.0" y="164.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="75.0" width="105.0" x="330.0" y="96.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
        <omgdc:Bounds height="55.0" width="105.0" x="310.0" y="360.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4">
        <omgdc:Bounds height="78.0" width="105.0" x="330.0" y="193.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="scripttask1" id="BPMNShape_scripttask1">
        <omgdc:Bounds height="89.0" width="121.0" x="60.0" y="136.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="parallelgateway1" id="BPMNShape_parallelgateway1">
        <omgdc:Bounds height="40.0" width="40.0" x="230.0" y="162.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="parallelgateway2" id="BPMNShape_parallelgateway2">
        <omgdc:Bounds height="40.0" width="40.0" x="480.0" y="160.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
        <omgdc:Bounds height="40.0" width="40.0" x="568.0" y="160.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask5" id="BPMNShape_usertask5">
        <omgdc:Bounds height="68.0" width="105.0" x="640.0" y="147.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="35.0" y="180.0"></omgdi:waypoint>
        <omgdi:waypoint x="60.0" y="180.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="181.0" y="180.0"></omgdi:waypoint>
        <omgdi:waypoint x="230.0" y="182.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="250.0" y="162.0"></omgdi:waypoint>
        <omgdi:waypoint x="250.0" y="137.0"></omgdi:waypoint>
        <omgdi:waypoint x="330.0" y="133.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="250.0" y="202.0"></omgdi:waypoint>
        <omgdi:waypoint x="250.0" y="233.0"></omgdi:waypoint>
        <omgdi:waypoint x="330.0" y="232.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="435.0" y="133.0"></omgdi:waypoint>
        <omgdi:waypoint x="500.0" y="137.0"></omgdi:waypoint>
        <omgdi:waypoint x="500.0" y="160.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
        <omgdi:waypoint x="435.0" y="232.0"></omgdi:waypoint>
        <omgdi:waypoint x="500.0" y="233.0"></omgdi:waypoint>
        <omgdi:waypoint x="500.0" y="200.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
        <omgdi:waypoint x="520.0" y="180.0"></omgdi:waypoint>
        <omgdi:waypoint x="568.0" y="180.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">
        <omgdi:waypoint x="588.0" y="200.0"></omgdi:waypoint>
        <omgdi:waypoint x="362.0" y="360.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13">
        <omgdi:waypoint x="362.0" y="360.0"></omgdi:waypoint>
        <omgdi:waypoint x="120.0" y="225.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow15" id="BPMNEdge_flow15">
        <omgdi:waypoint x="745.0" y="181.0"></omgdi:waypoint>
        <omgdi:waypoint x="790.0" y="181.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow16" id="BPMNEdge_flow16">
        <omgdi:waypoint x="415.0" y="387.0"></omgdi:waypoint>
        <omgdi:waypoint x="598.0" y="387.0"></omgdi:waypoint>
        <omgdi:waypoint x="807.0" y="199.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow17" id="BPMNEdge_flow17">
        <omgdi:waypoint x="608.0" y="180.0"></omgdi:waypoint>
        <omgdi:waypoint x="640.0" y="181.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

以下是工作流程内容模型:

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

    <!-- Optional meta-data about the model -->
    <description>...</description>
    <author>...</author>
    <version>...</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://.../model/workflow/1.0" prefix="scwf" />
    </namespaces>

    <types>

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

        <type name="scwf:activitiFirstReview">
            <parent>scwf:activitiReviewTask</parent>
        </type>

        <type name="scwf:activitiSecondReview">
            <parent>scwf:activitiReviewTask</parent>
        </type>

        <type name="scwf:activitiRevise">
            <parent>bpm:activitiOutcomeTask</parent>
            <properties>
                <property name="scwf: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://.../model/workflow/1.0}reviseOutcome</default>
                </property>
            </overrides>
        </type>

        <type name="scwf:activitiReviewTask">
            <parent>bpm:activitiOutcomeTask</parent>
            <properties>
                <property name="scwf: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://.../model/workflow/1.0}approveRejectOutcome</default>
                </property>
            </overrides>
        </type>

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

在我安装的本地计算机上:

  

Alfresco分享v5.2.d(r134641-b15,Aikau 1.0.101.3,Spring Surf   5.2.d,Spring WebScripts 6.13,Freemarker 2.3.20-alfresco-patched,Rhino 1.7R4-alfresco-patched,Yui 2.9.0-alfresco-20141223)

     

Alfresco Community v5.2.0(r134428-b13)schema 10005

一切正常......

但是,当我在服务器上安装系统时会出现问题,其中:

  

Alfresco Share v5.2.c(r133673-b12,Aikau 1.0.99,Spring Surf 5.2.c,   Spring WebScripts 6.11,Freemarker 2.3.20-alfresco-patched,Rhino   1.7R4-alfresco-patched,Yui 2.9.0-alfresco-20141223)

     

Alfresco Community v5.2.0(r133656-b12)schema 10005

在批准过程中,我收到以下错误消息:

  

org.activiti.engine.ActivitiException:使用的未知属性   表达式:$ {scwf_approveCount&lt; 2}

NB :错误仅在下一组处理后出现(无论是第一组还是第二组) - 例如,如果合同被第一组批准/拒绝,那么第二组不能既不赞同也不拒绝。

门户ecmarchitect说:

“您可能想知道为什么这是服务任务而不是脚本任务。在5.0.d中,Activiti中的底层JavaScript引擎从Rhino切换到Nashorn。这导致了与设置执行变量相关的问题。解决方法是使用服务任务。“

并显示了如何初始化变量的示例:

<serviceTask id="scripttask1" name="Submit" activiti:class="org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate">
  <extensionElements>
    <activiti:field name="script">
      <activiti:string><![CDATA[execution.setVariable('scwf_approveCount', 0);
          execution.setVariable('scwf_tpApproved', false);]]></activiti:string>
    </activiti:field>
  </extensionElements>
</serviceTask>

我发现了几个关于此问题的讨论,但是他们所描述的方法都没有对我的情况有所帮助:

例如,我尝试通过以下方式初始化变量:

...

<scriptTask id="scripttask1" name="Submit" scriptFormat="javascript" activiti:autoStoreVariables="true">
    <script>var scwf_approveCount = 0; var scwf_tpApproved = false;</script>
</scriptTask>

...

<scriptTask id="scripttask1" name="Submit" scriptFormat="javascript">
<script><![CDATA[var scwf_approveCount = 0; var scwf_tpApproved =
false;]]></script>
</scriptTask>

...

<scriptTask id="scripttask1" name="Submit" scriptFormat="javascript" activiti:autoStoreVariables="true">
    <script>execution.setVariable('scwf_approveCount', 0); execution.setVariable('scwf_tpApproved', false);</script>
</scriptTask>

...

我认为我需要在服务器上重新安装Alfresco以匹配本地安装。

还有其他方法可以解决这个问题吗?我非常感谢这些信息。谢谢大家。

其他信息:我安装了完全相同的系统。在服务器和我的本地计算机上:

  

Alfresco分享v5.2.d(r134641-b15,Aikau 1.0.101.3,Spring Surf   5.2.d,Spring WebScripts 6.13,Freemarker 2.3.20-alfresco-patched,Rhino 1.7R4-alfresco-patched,Yui 2.9.0-alfresco-20141223)

     

Alfresco Community v5.2.0(r134428-b13)schema 10005

但这很奇怪 - 本地一切正常,但在服务器上我再次遇到同样的错误:

  

org.activiti.engine.ActivitiException:使用的未知属性   表达式:$ {scwf_approveCount&lt; 2}

我比较了图表中和基础XML中的数据,它们是相同的。

1 个答案:

答案 0 :(得分:1)

scwf_approveCount您正在使用此属性,请确保已在工作流的模型文件中将此属性定义为scwf:approveCount 您正在使用此属性scwf_approveCount,它可能未在您的模型文件中定义。