cancel
Showing results for 
Search instead for 
Did you mean: 

Can't get past event type 'task-end' with javascript action

ericnk
Champ on-the-rise
Champ on-the-rise
Hello,

I have a workflow which won't transition because of a "task-end" event.  The event has a javascript action which assigns data to some variables.  In my efforts to trouble shoot the problem, I narrowed the problem to the "task-end" event.  When I removed this event from the workflow, the token advanced to the selected transition.

Here is the relevant section of the workflow….


   <task-node name="phaseTwo">
      <task name="stanwf:poPhaseTwoTask" swimlane="purchasingOperations">
         <event type="task-create">
            <script>
               if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
               if (bpm_workflowPriority != void)  taskInstance.priority = bpm_workflowPriority;
            </script>
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <runas>admin</runas>
               <script>
                  <variable name="phaseOneOption" access="read"/>
                  <variable name="orderDescription" access="read"/>
                  <variable name="phaseThreeRejected" access="read"/>
                  <variable name="bpm_package" access="read"/>
                  <variable name="initiator" access="read"/>
                  <expression>
                     <![CDATA[
                        <import resource="/Company Home/Data Dictionary/Scripts/powf-phase-two-task.js">
                     ]]>
                  </expression>
               </script>
            </action>
         </event>
         <event type="task-end">
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <runas>admin</runas>
               <script>
                  <variable name="phaseTwoEmail" access="read,write"/>
                  <variable name="people" access="read"/>
                  <variable name="tiComments" access="read,write"/>
                  <variable name="tiRejectReason" access="read,write"/>
                  <expression>
                     <![CDATA[
                        <import resource="/Company Home/Data Dictionary/Scripts/powf-phase-two-taskEnd.js">
                     ]]>
                  </expression>
               </script>
            </action>
         </event>
         <timer duedate="3 hours" >
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                  <variable name="orderDescription" access="read"/>
                  <variable name="bpm_package" access="read"/>
                  <variable name="initiator" access="read"/>
                  <expression>
                     <![CDATA[
                        <import resource="/Company Home/Data Dictionary/Scripts/powf-phase-two-timer.js">
                     ]]>
                  </expression>
               </script>
            </action>
         </timer>
      </task>
      <transition name="Vendor Quote" to="phaseThree">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <runas>admin</runas>
            <script>
               <variable name="phaseTwoOption" access="write"/>
               <expression>
                  phaseTwoOption = 2;
               </expression>
            </script>
         </action>
      </transition>
      <transition name="Complete" to="phaseThree">
         <script>
            <variable name="phaseTwoOption" access="write"/>
            <expression>
               phaseTwoOption = 1;
            </expression>
         </script>
      </transition>
      <transition name="Reject" to="phaseOne">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <runas>admin</runas>
            <script>
               <variable name="orderDescription" access="read"/>
               <variable name="bpm_package" access="read"/>
               <variable name="initiator" access="read"/>
               <variable name="phaseTwoEmail" access="read"/>
               <variable name="tiComments" access="read"/>
               <variable name="tiRejectReason" access="read"/>
               <expression>
                  <![CDATA[
                     <import resource="/Company Home/Data Dictionary/Scripts/powf-phase-two-reject-transition.js">
                  ]]>
               </expression>
            </script>
         </action>
      </transition>
   </task-node>

Here is the entire javascript file imported into the "task-end" event….


phaseTwoEmail = people.getPerson(taskInstance.actorId);
tiComments = taskInstance.comments.get(0).message;
tiRejectReason = taskInstance.getVariable("stanwf_rejectReason");

I've enabled the javascript debugger and run through the javascript code.  It all executes as expected, assigning data to the variables, but when I step past the last line of code, a "failed to signal transition…" error occurs.  During my trouble shooting procedures I added test lines of code to the end of the javascript file to make sure the error isn't occurring on the last line.  It steps past the last line normally and executes the added test lines, but again, after stepping past the last added line, the error occurs.  Here is the error if it helps….


org.alfresco.service.cmr.workflow.WorkflowException: 07020003 Failed to signal transition Reject from workflow task jbpm$36515

I'm using alfresco version 3.4.d.  I'm at my wits end trying to solve this.  Any suggestions or comments are appreciated.  Thank you.

Regards,

Eric
3 REPLIES 3

ericnk
Champ on-the-rise
Champ on-the-rise
After further investigation and exhaustive trouble shooting, it appears that a javascript action cannot contain more than one variable tag with write access.  In my opinion this is a serious deficiency in Alfresco's javascript support.  I don't know if this limitation extends to Java (I would assume not) or jPDL beanshell, but I've figured a way around it by getting the executionContext instance and setting and getting variables that way.

As an after thought, I'm disappointed in the lack of community support I've gotten on my last few posts.  The only post I've gotten a viable solution reply was posted back in April 2011.  I seem to remember viewing a webcast hosted by Jeff Potts not too long ago that promoted improved community support.  So far I'm not seeing it.  Of course it could be that no one has a solution, or it could be that no one has the time (there's that improved community support).  I wonder if it would hurt anyone to spend a couple of extra minutes answering a question they have knowledge of the solution to?

I will put some extra effort into reviewing posts and answering questions with my limited knowledge of the Alfresco ECM after this.

Anyway, it would appear this issue has been averted.  Not necessarily solved.


Regards,

Eric

sokolko
Champ in-the-making
Champ in-the-making
I've faced the same issue, too. Does anyone know a way to get this kind of script working? Maybe there is some JS class that can access all the business process data at some 'low level"?

ericnk
Champ on-the-rise
Champ on-the-rise
Sokolko,

Sorry for the delayed response.  It's been a while and I've since moved on to the activiti workflow language.  But, after getting my head wrapped around this issue and my solution, as I understand it, I was not able to set more than one global variable using javascript.  Although, if I remember correctly, I ran across a post that indicated I wasn't able to declare a reference to more than one global variable in the script block.  Like as follows….


         <event type="task-end">
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <runas>admin</runas>
               <script>
                  <variable name="phaseTwoEmail" access="read,write"/>
                  <variable name="people" access="read"/>
                  <variable name="tiComments" access="read,write"/>
                  <variable name="tiRejectReason" access="read,write"/>
                  <expression>
                     <![CDATA[
                        <import resource="/Company Home/Data Dictionary/Scripts/powf-phase-two-taskEnd.js">
                     ]]>
                  </expression>
               </script>
            </action>
         </event>

I had to abandon the variable reference tags and call on a method in the execution context as follows….


var phaseTwoEmail = people.getPerson(taskInstance.actorId).properties["cm:email"];
executionContext.setVariable("phaseTwoEmail", phaseTwoEmail);
var tiComments = taskInstance.comments.get(0).message;
executionContext.setVariable("tiComments", tiComments);
var tiRejectReason = taskInstance.getVariable("stanwf_rejectReason");
executionContext.setVariable("tiRejectReason", tiRejectReason);

I don't believe this issue exists in the activiti workflow language.  At least I haven't run into it thus far.  I hope this helps.


Regards,

Eric