AnsweredAssumed Answered

ReferenceError: 'initiator' is not defined.

Question asked by snc40845 on Jan 17, 2011
I created a workflow that an application is approved by multiple users.

First approver can approve without ReferenceError.
But second approver get 'ReferenceError: "initiator" is not defined' at below javascript code.
<foreach>#{people.getMembers(people.getGroup('GROUP_' + initiator.properties.userName + '_approver' + (approveCount + 1)))}</foreach>

Variables initiator and approveCount are undefiend at second user's approve action.

Could you tell me why variables become undefined?

Here are the process definition and error log.

<?xml version="1.0" encoding="UTF-8"?>

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="cowf:application">
   <swimlane name="initiator" />

   <start-state name="start">
      <task name="cowf:submitApplicationTask" swimlane="initiator" />
      <transition name="" to="Submit">
      </transition>
   </start-state>
   
   <node name="Submit">
      <event type="node-enter">
         <script>
            <variable name="approveCount" access="write"/>
            <expression>
               approveCount = 0;
            </expression>
         </script>
      </event>
      <transition name="" to="Check Group"></transition>
   </node>

   <node name="Check Group">
      <event type="node-enter">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <script>
            <expression>
            while (approveCount &lt; 4) {
               group = people.getGroup('GROUP_' +  initiator.properties.userName + '_approver' + (approveCount + 1));
               if (group) {
                  approveCount = approveCount;
                  break;
               }
               else {
                  approveCount = approveCount + 1;
               }
            }
            </expression>
            <variable name="approveCount" access="read,write"/>
            <variable name="initiator" access="read"/>
         </script>
      </action>
      </event>
      
      <transition to="Check Approver"></transition>
   </node>
   
   <decision name="Check Approver">
      <transition name="reject" to="Submit">
         <condition>#{approveCount == -1}</condition>
      </transition>
      
      <transition name="end" to="end">
         <condition>#{approveCount == 4}</condition>
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               logger.warn("to end!!!!!!!!!!!!");
            </script>
         </action>
      </transition>

      <transition name="next" to="Get Approver">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <expression>
                  logger.warn("to Get Approver!!!!!!!!!!!!!!");
                  logger.warn("to Get Approve count: " + approveCount);
               </expression>
               <variable name="approveCount" access="read"/>
            </script>
         </action>
      </transition>
   </decision>
   
   <node name="Get Approver">
      <action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
         <foreach>#{people.getMembers(people.getGroup('GROUP_' + initiator.properties.userName + '_approver' + (approveCount + 1)))}</foreach>
         <var>approver</var>
      </action>
      <transition to="Approve">
      </transition>
   </node>
   
   <task-node name="Approve">
      <task name="cowf:approveTask">
         <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
            <actor>#{approver}</actor>
         </assignment>
      </task>
      <transition name="approve" to="Check Group">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <variable name="approveCount" access="read,write"/>
               <expression>
                  approveCount = approveCount + 1;
               </expression>
            </script>
         </action>
      </transition>
      <transition name="reject" to="Check Group">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               logger.log("approver at reject: " + approver);
               logger.log("approve count at reject: " + approveCount);
            </script>
            <script>
               <variable name="approveCount" access="read,write"/>
               <expression>
                  approveCount = approveCount - 1;
               </expression>
            </script>
         </action>
      </transition>
   </task-node>
   
   <end-state name="end"></end-state>
</process-definition>


Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "initiator" is not defined. (AlfrescoJS#1)
   at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3350)
   at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3340)
   at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3413)
   at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1612)
   at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3314)
   at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2394)
   at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
   at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
   at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
   at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:173)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:472)

Outcomes