cancel
Showing results for 
Search instead for 
Did you mean: 

Calling workflow assignee's e-mail in Javascript

hanoul
Champ in-the-making
Champ in-the-making
I have added e-mail notification to my Web Site Submission workflow (Enterprise version 3.1).
At the moment, I have the recipient's e-mail address hard coded in my script. However, I would like to have the e-mail sent to the next 'assignee' in a serial review. How can I call the next serial reviewer's (assignee) e-mail address in Javascript?

My code at present is the following, and is placed inside the 'submitserialreview' decision node inside <configRoot>/alfresco/workflow/submit-processdefinition.xml:

    <decision name="submitserialreview">
       <transition name="endreview" to="endreview" />
       <transition name="review" to="serialreview">
         <condition>#{wcmwf_approveCnt &lt; wcmwf_reviewerCnt}</condition>
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <expression> 
               var mail = actions.create("mail");
               mail.parameters.to = "recipient_email@xxxx.com";
               mail.parameters.subject = "New Alfresco workflow submission: " + wcmwf_label + " by " + person.properties.userName;
               mail.parameters.from = initiator.properties["cm:email"];
               mail.parameters.text = person.properties.firstName + " " + person.properties.lastName + " has submitted the following content for your approval";
               mail.execute(bpm_package);               
               </expression>
            </script>
         </action>
       </transition>
    </decision>
10 REPLIES 10

jayjayecl
Confirmed Champ
Confirmed Champ
Hi, can you please post the full processDefinition.xml ?

hanoul
Champ in-the-making
Champ in-the-making
Thanks JayJay,

Here's one working versin of my submit-processdefinition.xml. In this version, the e-mail is sent to all members of the Sample2 project content managers group. But what I want to achieve is send an e-mail to the next reviewer in line in a serial review process, as determined by the serial workflow setting:


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

<!– This describes a process for submitting changed content in a user –>
<!– sandbox, via an approver, to the staging sandbox. –>

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wcmwf:submit">

    <swimlane name="initiator"/>

    <!–              –>
    <!– Start Review –>
    <!–              –>

    <start-state name="start">
        <task name="wcmwf:submitReviewTask" swimlane="initiator"/>
        <transition name="" to="initialise" />
    </start-state>
   
  <swimlane name="assignee">
    <assignment actor-id="#{bpm_assignee.properties['cm:userName']}"/>
  </swimlane>

    <decision name="initialise">
        <event type="node-enter">
            <script>
                <variable name="wcmwf_reviewCycle" access="write"/>
                <expression>
                   wcmwf_reviewCycle = 1;
                </expression>
            </script>
        </event>       
        <transition name="" to="serialorparallel" />
        <transition name="checklinks" to="checklinks">
           <condition>#{wcmwf_validateLinks != null &amp;&amp; wcmwf_validateLinks == true}</condition>
        </transition>
    </decision>
   
    <!–                                –>
    <!– Validate Links being submitted –>
    <!–                                –>
   
    <decision name="checklinks">
        <event type="node-enter">
            <action class="org.alfresco.repo.avm.wf.AVMSubmitLinkChecker" />
        </event>
        <transition name="brokenlinkspresent" to="verifybrokenlinks" />
        <transition name="nobrokenlinks" to="serialorparallel" >
            <condition>#{wcmwf_brokenLinks == 0}</condition>
        </transition>
    </decision>
   
    <task-node name="verifybrokenlinks">
        <task name="wcmwf:verifyBrokenLinksTask" swimlane="initiator" />
        <transition name="abort" to="end" />
        <transition name="continue" to="serialorparallel" />
    </task-node>

    <!–                                      –>
    <!– Split into Serial or Parallel Review –>
    <!–                                      –>

    <decision name="serialorparallel">
       <event type="node-enter">
            <script>
               <variable name="wcmwf_reviewerCnt" access="write"/>
               <variable name="wcmwf_approveCnt" access="write"/>
               <variable name="wcmwf_reviewType" access="write"/>
               <expression>
                  wcmwf_reviewerCnt = bpm_assignees.size();
                  wcmwf_approveCnt = 0;
                  wcmwf_reviewType = wcmwf_submitReviewType;
               </expression>
            </script>
       </event>

       <transition name="serial" to="submitserialreview" />
       <transition name="parallel" to="submitparallelreview">
          <condition>#{wcmwf_reviewType == "Parallel"}</condition>
       </transition>
    </decision>  


    <!–               –>
    <!– Serial Review –>
    <!–               –>
      <task name="wcmwf:submitSerialReview" swimlane="assignee"></task>
   
    <decision name="submitserialreview">
       <transition name="endreview" to="endreview" />
       <transition name="review" to="serialreview">
         <condition>#{wcmwf_approveCnt &lt; wcmwf_reviewerCnt}</condition>
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <expression>
              for each (user in people.getMembers(people.getGroup('GROUP_Sample2-ContentManager'), false)){
               var mail = actions.create("mail");
               mail.parameters.to = user.properties["cm:email"];
               mail.parameters.subject = "New Alfresco workflow submission: " + wcmwf_label + " by " + person.properties.userName;
               mail.parameters.from = initiator.properties["cm:email"];
               mail.parameters.text = "Dear " +  ":\u000D" + person.properties.firstName + " " + person.properties.lastName + " has submitted the following content in Alfresco for your approval:\u000D" + bpm_workflowDescription;
               mail.execute(bpm_package);
               }
               </expression>
            </script>
         </action>
       </transition>
    </decision>  

    <task-node name="serialreview">
        <task name="wcmwf:reviewTask">
           <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
              <actor>#{bpm_assignees.get(wcmwf_approveCnt)}</actor>
           </assignment>
           <event type="task-assign">
              <script>
                 if (wcmwf_reviewCycle > 1)
                    taskInstance.description = taskInstance.description + " (" + wcmwf_reviewCycle + ")";
              </script>
           </event>          
        </task>

        <transition name="approve" to="submitserialreview">
           <script>
              <variable name="wcmwf_approveCnt" access="read, write"/>
              <expression>
                 wcmwf_approveCnt = wcmwf_approveCnt + 1;
              </expression>
           </script>
        </transition>
        <transition name="reject" to="endreview" />
    </task-node>


    <!–                 –>
    <!– Parallel Review –>
    <!–                 –>

    <node name="submitparallelreview">
        <action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
            <foreach>#{bpm_assignees}</foreach>
            <var>reviewer</var>
        </action>
        <transition name="review" to="parallelreview" />
    </node>

    <task-node name="parallelreview">
        <task name="wcmwf:parallelReviewTask">
           <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
              <actor>#{reviewer}</actor>
           </assignment>
           <event type="task-assign">
              <script>
                 if (wcmwf_reviewCycle > 1)
                    taskInstance.description = taskInstance.description + " (" + wcmwf_reviewCycle + ")";
              </script>
           </event>          
        </task>
        <transition name="approve" to="joinparallelreview">
            <script>
                <variable name="wcmwf_approveCnt" access="read,write" />
                <expression>
                    wcmwf_approveCnt = wcmwf_approveCnt +1;
                </expression>
            </script>
        </transition>
        <transition name="reject" to="joinparallelreview" />
    </task-node>

    <join name="joinparallelreview">
        <transition to="endreview" />
    </join>


    <!–                –>
    <!– End the Review –>
    <!–                –>

    <decision name="endreview">
       <transition name="rejected" to="rejected" />
       <transition name="approved" to="onapprove">
           <condition>#{wcmwf_approveCnt == wcmwf_reviewerCnt}</condition>
       </transition>
    </decision>  

    <task-node name="rejected">
        <task name="wcmwf:rejectedTask" swimlane="initiator" >
            <event type="task-assign">
                <script>
                    if (wcmwf_reviewCycle > 1)
                        taskInstance.description = taskInstance.description + " (" + wcmwf_reviewCycle + ")";
                </script>
            </event>
        </task>
        <transition name="abort" to="end" />
        <transition name="resubmit" to="serialorparallel">        <!– restart review process (next cycle) –>
           <script>
               <variable name="wcmwf_reviewCycle" access="read,write" />
               <expression>
                   wcmwf_reviewCycle = wcmwf_reviewCycle +1;
               </expression>
           </script>
        </transition>
    </task-node>

    <decision name="onapprove">
       <transition name="launchnow" to="submitted" />
       <transition name="launchpending" to="submitpending">
           <condition>#{wcmwf_launchDate != null}</condition>
       </transition>
    </decision>

    <task-node name="submitpending" end-tasks="true">
        <task name="wcmwf:submitpendingTask" swimlane="initiator">
           <event type="task-create">
              <script>
                 taskInstance.dueDate = wcmwf_launchDate;
              </script>
           </event>       
           <timer duedate="#{wcmwf_launchDate}" transition="launch" >
               <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                   <script>
                      logger.log("WCM Submission " + bpm_workflowDescription + " submitted at " + wcmwf_launchDate + " by " + person.properties.userName);
                   </script>
               </action>
           </timer>
        </task>
        <transition name="cancel" to="submitcancelled" />
        <transition name="launch" to="submitted" />
    </task-node>

    <task-node name="submitcancelled">
        <task name="wcmwf:submitcancelledTask" swimlane="initiator" />
        <transition name="" to="end" />
    </task-node>

    <task-node name="submitted" end-tasks="true">
        <task name="wcmwf:submittedTask" swimlane="initiator">
            <timer duedate="5 seconds" transition="onsubmit">
                <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                    <script>
                        logger.log("WCM Submit Process: Triggering submit for " + bpm_workflowDescription);
                    </script>
                </action>
            </timer>

           <event type="task-end">
                <script>
                   <variable name="submitfailed" access="write"/>
                   <expression>submitfailed = false;</expression>
                </script>
          
               <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                   <script>
                       logger.log("WCM Submit Process: Start submit for " + bpm_workflowDescription + " (by " + person.properties.userName + ")");
                   </script>
               </action>
   
               <action class="org.alfresco.repo.avm.wf.AVMSubmitPackageHandler"/>
               <action class="org.alfresco.repo.avm.wf.AVMDeployHandler"/>
             
               <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                   <script>
                        logger.log("WCM Submit Process: End submit for " + bpm_workflowDescription + " (by " + person.properties.userName + ")");
                   </script>
               </action>
           </event>
        </task>
        <transition name="onsubmit" to="checkfailedsubmit">
         <exception-handler>
                <script>
               <variable name="submitfailed" access="write"/>
               <expression>
                        logger.log("WCM Submit Process: Submit failed for " + bpm_workflowDescription + " (by " + person.properties.userName + ")");
                  submitfailed = true;
               </expression>
            </script>
         </exception-handler>
        </transition>
    </task-node>

    <decision name="checkfailedsubmit">
        <transition name="failure" to="submitfailed">
           <condition>#{submitfailed == true}</condition>
        </transition>
        <transition name="success" to="end">
           <condition>#{submitfailed == false}</condition>
        </transition>
    </decision>

    <task-node name="submitfailed">
        <task name="wcmwf:submitfailedTask" swimlane="initiator"/>
        <transition name="" to="end"/>
    </task-node>

    <!–                 –>
    <!– End the Process –>
    <!–                 –>

    <end-state name="end"/>
   
    <event type="process-end">
        <action class="org.alfresco.repo.avm.wf.AVMRemoveAllSrcWebappsHandler"/>
        <action class="org.alfresco.repo.avm.wf.AVMReleaseTestServerHandler"/>
        <action class="org.alfresco.repo.avm.wf.AVMRemoveWFStoreHandler"/>
    </event>

</process-definition>

jayjayecl
Confirmed Champ
Confirmed Champ
Try the following (should not be working - because I could not test it - but giving you ideas) :



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

<!– This describes a process for submitting changed content in a user –>
<!– sandbox, via an approver, to the staging sandbox. –>

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wcmwf:submit">

    <swimlane name="initiator"/>

    <!–              –>
    <!– Start Review –>
    <!–              –>

    <start-state name="start">
        <task name="wcmwf:submitReviewTask" swimlane="initiator"/>
        <transition name="" to="initialise" />
    </start-state>
  
  <swimlane name="assignee">
    <assignment actor-id="#{bpm_assignee.properties['cm:userName']}"/>
  </swimlane>

<swimlane name="emailedAssignee">
    <assignment actor-id="#{bpm_assignees.get(wcmwf_approveCnt)}"/>
  </swimlane>

    <decision name="initialise">
        <event type="node-enter">
            <script>
                <variable name="wcmwf_reviewCycle" access="write"/>
                <expression>
                   wcmwf_reviewCycle = 1;
                </expression>
            </script>
        </event>      
        <transition name="" to="serialorparallel" />
        <transition name="checklinks" to="checklinks">
           <condition>#{wcmwf_validateLinks != null &amp;&amp; wcmwf_validateLinks == true}</condition>
        </transition>
    </decision>
  
    <!–                                –>
    <!– Validate Links being submitted –>
    <!–                                –>
  
    <decision name="checklinks">
        <event type="node-enter">
            <action class="org.alfresco.repo.avm.wf.AVMSubmitLinkChecker" />
        </event>
        <transition name="brokenlinkspresent" to="verifybrokenlinks" />
        <transition name="nobrokenlinks" to="serialorparallel" >
            <condition>#{wcmwf_brokenLinks == 0}</condition>
        </transition>
    </decision>
  
    <task-node name="verifybrokenlinks">
        <task name="wcmwf:verifyBrokenLinksTask" swimlane="initiator" />
        <transition name="abort" to="end" />
        <transition name="continue" to="serialorparallel" />
    </task-node>

    <!–                                      –>
    <!– Split into Serial or Parallel Review –>
    <!–                                      –>

    <decision name="serialorparallel">
       <event type="node-enter">
            <script>
               <variable name="wcmwf_reviewerCnt" access="write"/>
               <variable name="wcmwf_approveCnt" access="write"/>
               <variable name="wcmwf_reviewType" access="write"/>
               <expression>
                  wcmwf_reviewerCnt = bpm_assignees.size();
                  wcmwf_approveCnt = 0;
                  wcmwf_reviewType = wcmwf_submitReviewType;
               </expression>
            </script>
       </event>

       <transition name="serial" to="submitserialreview" />
       <transition name="parallel" to="submitparallelreview">
          <condition>#{wcmwf_reviewType == "Parallel"}</condition>
       </transition>
    </decision>  


    <!–               –>
    <!– Serial Review –>
    <!–               –>
      <task name="wcmwf:submitSerialReview" swimlane="assignee"></task>
  
    <decision name="submitserialreview">
       <transition name="endreview" to="endreview" />
       <transition name="review" to="serialreview">
         <condition>#{wcmwf_approveCnt &lt; wcmwf_reviewerCnt}</condition>
        
       </transition>
    </decision>  

    <task-node name="serialreview">
        <task name="wcmwf:reviewTask" swimlane="emailedAssignee">
          
           <event type="task-assign">
              <script>
                 if (wcmwf_reviewCycle > 1)
                    taskInstance.description = taskInstance.description + " (" + wcmwf_reviewCycle + ")";
              </script>


              <action class="org.alfresco.module.sncfgrimoireprocessamp.repo.workflow.jbpm.AlfrescoJavaScriptGP">
                <runas>admin</runas>      
               <script>
                    <variable name="emailedAssignee" access="read" />
                   <expression>
                              var emailAddress = emailedAssignee.properties.email;
                              // YOUR CODE HERE TO SEND THE EMAIL
                      </expression>
                </script>
             </action>

           </event>          
        </task>

        <transition name="approve" to="submitserialreview">
           <script>
              <variable name="wcmwf_approveCnt" access="read, write"/>
              <expression>
                 wcmwf_approveCnt = wcmwf_approveCnt + 1;
              </expression>
           </script>
        </transition>
        <transition name="reject" to="endreview" />
    </task-node>


    <!–                 –>
    <!– Parallel Review –>
    <!–                 –>

    <node name="submitparallelreview">
        <action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
            <foreach>#{bpm_assignees}</foreach>
            <var>reviewer</var>
        </action>
        <transition name="review" to="parallelreview" />
    </node>

    <task-node name="parallelreview">
        <task name="wcmwf:parallelReviewTask">
           <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
              <actor>#{reviewer}</actor>
           </assignment>
           <event type="task-assign">
              <script>
                 if (wcmwf_reviewCycle > 1)
                    taskInstance.description = taskInstance.description + " (" + wcmwf_reviewCycle + ")";
              </script>
           </event>          
        </task>
        <transition name="approve" to="joinparallelreview">
            <script>
                <variable name="wcmwf_approveCnt" access="read,write" />
                <expression>
                    wcmwf_approveCnt = wcmwf_approveCnt +1;
                </expression>
            </script>
        </transition>
        <transition name="reject" to="joinparallelreview" />
    </task-node>

    <join name="joinparallelreview">
        <transition to="endreview" />
    </join>


    <!–                –>
    <!– End the Review –>
    <!–                –>

    <decision name="endreview">
       <transition name="rejected" to="rejected" />
       <transition name="approved" to="onapprove">
           <condition>#{wcmwf_approveCnt == wcmwf_reviewerCnt}</condition>
       </transition>
    </decision>  

    <task-node name="rejected">
        <task name="wcmwf:rejectedTask" swimlane="initiator" >
            <event type="task-assign">
                <script>
                    if (wcmwf_reviewCycle > 1)
                        taskInstance.description = taskInstance.description + " (" + wcmwf_reviewCycle + ")";
                </script>
            </event>
        </task>
        <transition name="abort" to="end" />
        <transition name="resubmit" to="serialorparallel">        <!– restart review process (next cycle) –>
           <script>
               <variable name="wcmwf_reviewCycle" access="read,write" />
               <expression>
                   wcmwf_reviewCycle = wcmwf_reviewCycle +1;
               </expression>
           </script>
        </transition>
    </task-node>

    <decision name="onapprove">
       <transition name="launchnow" to="submitted" />
       <transition name="launchpending" to="submitpending">
           <condition>#{wcmwf_launchDate != null}</condition>
       </transition>
    </decision>

    <task-node name="submitpending" end-tasks="true">
        <task name="wcmwf:submitpendingTask" swimlane="initiator">
           <event type="task-create">
              <script>
                 taskInstance.dueDate = wcmwf_launchDate;
              </script>
           </event>      
           <timer duedate="#{wcmwf_launchDate}" transition="launch" >
               <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                   <script>
                      logger.log("WCM Submission " + bpm_workflowDescription + " submitted at " + wcmwf_launchDate + " by " + person.properties.userName);
                   </script>
               </action>
           </timer>
        </task>
        <transition name="cancel" to="submitcancelled" />
        <transition name="launch" to="submitted" />
    </task-node>

    <task-node name="submitcancelled">
        <task name="wcmwf:submitcancelledTask" swimlane="initiator" />
        <transition name="" to="end" />
    </task-node>

    <task-node name="submitted" end-tasks="true">
        <task name="wcmwf:submittedTask" swimlane="initiator">
            <timer duedate="5 seconds" transition="onsubmit">
                <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                    <script>
                        logger.log("WCM Submit Process: Triggering submit for " + bpm_workflowDescription);
                    </script>
                </action>
            </timer>

           <event type="task-end">
                <script>
                   <variable name="submitfailed" access="write"/>
                   <expression>submitfailed = false;</expression>
                </script>
         
               <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                   <script>
                       logger.log("WCM Submit Process: Start submit for " + bpm_workflowDescription + " (by " + person.properties.userName + ")");
                   </script>
               </action>
  
               <action class="org.alfresco.repo.avm.wf.AVMSubmitPackageHandler"/>
               <action class="org.alfresco.repo.avm.wf.AVMDeployHandler"/>
             
               <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                   <script>
                        logger.log("WCM Submit Process: End submit for " + bpm_workflowDescription + " (by " + person.properties.userName + ")");
                   </script>
               </action>
           </event>
        </task>
        <transition name="onsubmit" to="checkfailedsubmit">
         <exception-handler>
                <script>
               <variable name="submitfailed" access="write"/>
               <expression>
                        logger.log("WCM Submit Process: Submit failed for " + bpm_workflowDescription + " (by " + person.properties.userName + ")");
                  submitfailed = true;
               </expression>
            </script>
         </exception-handler>
        </transition>
    </task-node>

    <decision name="checkfailedsubmit">
        <transition name="failure" to="submitfailed">
           <condition>#{submitfailed == true}</condition>
        </transition>
        <transition name="success" to="end">
           <condition>#{submitfailed == false}</condition>
        </transition>
    </decision>

    <task-node name="submitfailed">
        <task name="wcmwf:submitfailedTask" swimlane="initiator"/>
        <transition name="" to="end"/>
    </task-node>

    <!–                 –>
    <!– End the Process –>
    <!–                 –>

    <end-state name="end"/>
  
    <event type="process-end">
        <action class="org.alfresco.repo.avm.wf.AVMRemoveAllSrcWebappsHandler"/>
        <action class="org.alfresco.repo.avm.wf.AVMReleaseTestServerHandler"/>
        <action class="org.alfresco.repo.avm.wf.AVMRemoveWFStoreHandler"/>
    </event>

</process-definition>



Changes I made :
- declaring a new swimlane "emailedAssignee", that will be useful in the serialReview Task, in order to get the task handler's email property.
- putting email sending process in the serialReview task-assign event
- getting the email of the serialreview task's owner using the variable "emailedAssignee"

try it and show us the future stacktrace (there will be one, but we'ell get over it)
Smiley Happy

hanoul
Champ in-the-making
Champ in-the-making
Hi JayJay,

Thanks. I tried your suggestion in a serial workflow with only one reviewer. When a user submits a document through the workflow, Alfresco comes up with the following error message:

javax.faces.FacesException: Error calling action method of component with id dialog:finish-button
caused by:
javax.faces.el.EvaluationException: Exception while invoking expression #{DialogManager.finish}
caused by:
org.alfresco.error.AlfrescoRuntimeException: Failed to submit to workflow
caused by:
org.alfresco.service.cmr.workflow.WorkflowException: Failed to signal transition 'null' from workflow task 'jbpm$244'
caused by:
org.jbpm.graph.def.DelegationException: couldn't evaluate expression '#{bpm_assignees.get(wcmwf_approveCnt)}'
caused by:
org.jbpm.JbpmException: couldn't evaluate expression '#{bpm_assignees.get(wcmwf_approveCnt)}'
caused by:
org.jbpm.jpdl.el.ELException: Encountered "(", expected one of ["}", ".", ">", "gt", "<", "lt", "==", "eq", "<=", "le", ">=", "ge", "!=", "ne", "[", "+", "-", "*", "/", "div", "%", "mod", "and", "&&", "or", "||", "?"]

My submit_processdefinition is as follows:
<?xml version="1.0" encoding="UTF-8"?>

<!– This describes a process for submitting changed content in a user –>
<!– sandbox, via an approver, to the staging sandbox. –>

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wcmwf:submit">

    <swimlane name="initiator"/>

    <!–              –>
    <!– Start Review –>
    <!–              –>

    <start-state name="start">
        <task name="wcmwf:submitReviewTask" swimlane="initiator"/>
        <transition name="" to="initialise" />
    </start-state>
  
  <swimlane name="assignee">
    <assignment actor-id="#{bpm_assignee.properties['cm:userName']}"/>
  </swimlane>

<swimlane name="emailedAssignee">
    <assignment actor-id="#{bpm_assignees.get(wcmwf_approveCnt)}"/>
  </swimlane>

    <decision name="initialise">
        <event type="node-enter">
            <script>
                <variable name="wcmwf_reviewCycle" access="write"/>
                <expression>
                   wcmwf_reviewCycle = 1;
                </expression>
            </script>
        </event>      
        <transition name="" to="serialorparallel" />
        <transition name="checklinks" to="checklinks">
           <condition>#{wcmwf_validateLinks != null &amp;&amp; wcmwf_validateLinks == true}</condition>
        </transition>
    </decision>
  
    <!–                                –>
    <!– Validate Links being submitted –>
    <!–                                –>
  
    <decision name="checklinks">
        <event type="node-enter">
            <action class="org.alfresco.repo.avm.wf.AVMSubmitLinkChecker" />
        </event>
        <transition name="brokenlinkspresent" to="verifybrokenlinks" />
        <transition name="nobrokenlinks" to="serialorparallel" >
            <condition>#{wcmwf_brokenLinks == 0}</condition>
        </transition>
    </decision>
  
    <task-node name="verifybrokenlinks">
        <task name="wcmwf:verifyBrokenLinksTask" swimlane="initiator" />
        <transition name="abort" to="end" />
        <transition name="continue" to="serialorparallel" />
    </task-node>

    <!–                                      –>
    <!– Split into Serial or Parallel Review –>
    <!–                                      –>

    <decision name="serialorparallel">
       <event type="node-enter">
            <script>
               <variable name="wcmwf_reviewerCnt" access="write"/>
               <variable name="wcmwf_approveCnt" access="write"/>
               <variable name="wcmwf_reviewType" access="write"/>
               <expression>
                  wcmwf_reviewerCnt = bpm_assignees.size();
                  wcmwf_approveCnt = 0;
                  wcmwf_reviewType = wcmwf_submitReviewType;
               </expression>
            </script>
       </event>

       <transition name="serial" to="submitserialreview" />
       <transition name="parallel" to="submitparallelreview">
          <condition>#{wcmwf_reviewType == "Parallel"}</condition>
       </transition>
    </decision>  


    <!–               –>
    <!– Serial Review –>
    <!–               –>
      <task name="wcmwf:submitSerialReview" swimlane="assignee"></task>
  
    <decision name="submitserialreview">
       <transition name="endreview" to="endreview" />
       <transition name="review" to="serialreview">
         <condition>#{wcmwf_approveCnt &lt; wcmwf_reviewerCnt}</condition>
        
       </transition>
    </decision>  

    <task-node name="serialreview">
        <task name="wcmwf:reviewTask" swimlane="emailedAssignee">
          
           <event type="task-assign">
              <script>
                 if (wcmwf_reviewCycle > 1)
                    taskInstance.description = taskInstance.description + " (" + wcmwf_reviewCycle + ")";
              </script>


              <action class="org.alfresco.module.sncfgrimoireprocessamp.repo.workflow.jbpm.AlfrescoJavaScriptGP">
                <runas>admin</runas>     
               <script>
                    <variable name="emailedAssignee" access="read" />
                   <expression>
                    var emailAddress = emailedAssignee.properties.email;
               var mail = actions.create("mail");
               mail.parameters.to = emailAddress;
               mail.parameters.subject = "New Alfresco workflow submission: " + wcmwf_label + " by " + person.properties.userName;
               mail.parameters.from = person.properties.email;
               mail.parameters.text = "Dear " +  ":\u000D" + person.properties.firstName + " " + person.properties.lastName + " has submitted the following content in Alfresco for your approval:\u000D" + bpm_workflowDescription;
               mail.execute(bpm_package);
                    </expression>
                </script>
             </action>

           </event>          
        </task>

        <transition name="approve" to="submitserialreview">
           <script>
              <variable name="wcmwf_approveCnt" access="read, write"/>
              <expression>
                 wcmwf_approveCnt = wcmwf_approveCnt + 1;
              </expression>
           </script>
        </transition>
        <transition name="reject" to="endreview" />
    </task-node>


    <!–                 –>
    <!– Parallel Review –>
    <!–                 –>

    <node name="submitparallelreview">
        <action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
            <foreach>#{bpm_assignees}</foreach>
            <var>reviewer</var>
        </action>
        <transition name="review" to="parallelreview" />
    </node>

    <task-node name="parallelreview">
        <task name="wcmwfSmiley TonguearallelReviewTask">
           <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
              <actor>#{reviewer}</actor>
           </assignment>
           <event type="task-assign">
              <script>
                 if (wcmwf_reviewCycle > 1)
                    taskInstance.description = taskInstance.description + " (" + wcmwf_reviewCycle + ")";
              </script>
           </event>          
        </task>
        <transition name="approve" to="joinparallelreview">
            <script>
                <variable name="wcmwf_approveCnt" access="read,write" />
                <expression>
                    wcmwf_approveCnt = wcmwf_approveCnt +1;
                </expression>
            </script>
        </transition>
        <transition name="reject" to="joinparallelreview" />
    </task-node>

    <join name="joinparallelreview">
        <transition to="endreview" />
    </join>


    <!–                –>
    <!– End the Review –>
    <!–                –>

    <decision name="endreview">
       <transition name="rejected" to="rejected" />
       <transition name="approved" to="onapprove">
           <condition>#{wcmwf_approveCnt == wcmwf_reviewerCnt}</condition>
       </transition>
    </decision>  

    <task-node name="rejected">
        <task name="wcmwf:rejectedTask" swimlane="initiator" >
            <event type="task-assign">
                <script>
                    if (wcmwf_reviewCycle > 1)
                        taskInstance.description = taskInstance.description + " (" + wcmwf_reviewCycle + ")";
                </script>
            </event>
        </task>
        <transition name="abort" to="end" />
        <transition name="resubmit" to="serialorparallel">        <!– restart review process (next cycle) –>
           <script>
               <variable name="wcmwf_reviewCycle" access="read,write" />
               <expression>
                   wcmwf_reviewCycle = wcmwf_reviewCycle +1;
               </expression>
           </script>
        </transition>
    </task-node>

    <decision name="onapprove">
       <transition name="launchnow" to="submitted" />
       <transition name="launchpending" to="submitpending">
           <condition>#{wcmwf_launchDate != null}</condition>
       </transition>
    </decision>

    <task-node name="submitpending" end-tasks="true">
        <task name="wcmwf:submitpendingTask" swimlane="initiator">
           <event type="task-create">
              <script>
                 taskInstance.dueDate = wcmwf_launchDate;
              </script>
           </event>      
           <timer duedate="#{wcmwf_launchDate}" transition="launch" >
               <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                   <script>
                      logger.log("WCM Submission " + bpm_workflowDescription + " submitted at " + wcmwf_launchDate + " by " + person.properties.userName);
                   </script>
               </action>
           </timer>
        </task>
        <transition name="cancel" to="submitcancelled" />
        <transition name="launch" to="submitted" />
    </task-node>

    <task-node name="submitcancelled">
        <task name="wcmwf:submitcancelledTask" swimlane="initiator" />
        <transition name="" to="end" />
    </task-node>

    <task-node name="submitted" end-tasks="true">
        <task name="wcmwf:submittedTask" swimlane="initiator">
            <timer duedate="5 seconds" transition="onsubmit">
                <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                    <script>
                        logger.log("WCM Submit Process: Triggering submit for " + bpm_workflowDescription);
                    </script>
                </action>
            </timer>

           <event type="task-end">
                <script>
                   <variable name="submitfailed" access="write"/>
                   <expression>submitfailed = false;</expression>
                </script>
         
               <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                   <script>
                       logger.log("WCM Submit Process: Start submit for " + bpm_workflowDescription + " (by " + person.properties.userName + ")");
                   </script>
               </action>
  
               <action class="org.alfresco.repo.avm.wf.AVMSubmitPackageHandler"/>
               <action class="org.alfresco.repo.avm.wf.AVMDeployHandler"/>
             
               <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                   <script>
                        logger.log("WCM Submit Process: End submit for " + bpm_workflowDescription + " (by " + person.properties.userName + ")");
                   </script>
               </action>
           </event>
        </task>
        <transition name="onsubmit" to="checkfailedsubmit">
         <exception-handler>
                <script>
               <variable name="submitfailed" access="write"/>
               <expression>
                        logger.log("WCM Submit Process: Submit failed for " + bpm_workflowDescription + " (by " + person.properties.userName + ")");
                  submitfailed = true;
               </expression>
            </script>
         </exception-handler>
        </transition>
    </task-node>

    <decision name="checkfailedsubmit">
        <transition name="failure" to="submitfailed">
           <condition>#{submitfailed == true}</condition>
        </transition>
        <transition name="success" to="end">
           <condition>#{submitfailed == false}</condition>
        </transition>
    </decision>

    <task-node name="submitfailed">
        <task name="wcmwf:submitfailedTask" swimlane="initiator"/>
        <transition name="" to="end"/>
    </task-node>

    <!–                 –>
    <!– End the Process –>
    <!–                 –>

    <end-state name="end"/>
  
    <event type="process-end">
        <action class="org.alfresco.repo.avm.wf.AVMRemoveAllSrcWebappsHandler"/>
        <action class="org.alfresco.repo.avm.wf.AVMReleaseTestServerHandler"/>
        <action class="org.alfresco.repo.avm.wf.AVMRemoveWFStoreHandler"/>
    </event>

</process-definition>

Basically I copied your code and added my e-mail creation code to the part you suggested. It looks like the expression '#{bpm_assignees.get(wcmwf_approveCnt)}' can not be evaluated at the start state, which is kind of understandable. I am thinking the e-mail for the first workflow submission should still be generated where I had originally put it (in 'submitSerialReview'), and subsequent e-mails should be generated in the serialreview task. The big problem is to get the next assignee's e-mail address.

Thanks for your help.

jayjayecl
Confirmed Champ
Confirmed Champ
Try the following

swimlane :


<swimlane name="emailedAssignee">
<assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
<actor>#{bpm_assignees.get(wcmwf_approveCnt)}</actor>
</assignment>
</swimlane>

And change the call to AlfrescoJavascriptGP (custom code, sorry for that) back to AlfrescoJavascript (with the proper package)

If this does not work, go to the next post

jayjayecl
Confirmed Champ
Confirmed Champ
Try the following :


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

<!– This describes a process for submitting changed content in a user –>
<!– sandbox, via an approver, to the staging sandbox. –>

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wcmwf:submit">

<swimlane name="initiator"/>

<!– –>
<!– Start Review –>
<!– –>

<start-state name="start">
<task name="wcmwf:submitReviewTask" swimlane="initiator"/>
<transition name="" to="initialise" />
</start-state>

<swimlane name="assignee">
<assignment actor-id="#{bpm_assignee.properties['cm:userName']}"/>
</swimlane>


<decision name="initialise">
<event type="node-enter">
<script>
<variable name="wcmwf_reviewCycle" access="write"/>
<expression>
wcmwf_reviewCycle = 1;
</expression>
</script>
</event>
<transition name="" to="serialorparallel" />
<transition name="checklinks" to="checklinks">
<condition>#{wcmwf_validateLinks != null &amp;&amp; wcmwf_validateLinks == true}</condition>
</transition>
</decision>

<!– –>
<!– Validate Links being submitted –>
<!– –>

<decision name="checklinks">
<event type="node-enter">
<action class="org.alfresco.repo.avm.wf.AVMSubmitLinkChecker" />
</event>
<transition name="brokenlinkspresent" to="verifybrokenlinks" />
<transition name="nobrokenlinks" to="serialorparallel" >
<condition>#{wcmwf_brokenLinks == 0}</condition>
</transition>
</decision>

<task-node name="verifybrokenlinks">
<task name="wcmwf:verifyBrokenLinksTask" swimlane="initiator" />
<transition name="abort" to="end" />
<transition name="continue" to="serialorparallel" />
</task-node>

<!– –>
<!– Split into Serial or Parallel Review –>
<!– –>

<decision name="serialorparallel">
<event type="node-enter">
<script>
<variable name="wcmwf_reviewerCnt" access="write"/>
<variable name="wcmwf_approveCnt" access="write"/>
<variable name="wcmwf_reviewType" access="write"/>
<expression>
wcmwf_reviewerCnt = bpm_assignees.size();
wcmwf_approveCnt = 0;
wcmwf_reviewType = wcmwf_submitReviewType;
</expression>
</script>
</event>

<transition name="serial" to="submitserialreview" />
<transition name="parallel" to="submitparallelreview">
<condition>#{wcmwf_reviewType == "Parallel"}</condition>
</transition>
</decision>


<!– –>
<!– Serial Review –>
<!– –>
<task name="wcmwf:submitSerialReview" swimlane="assignee"></task>

<decision name="submitserialreview">
<transition name="endreview" to="endreview" />
<transition name="review" to="serialreview">
<condition>#{wcmwf_approveCnt &lt; wcmwf_reviewerCnt}</condition>

</transition>
</decision>

<task-node name="serialreview">
<task name="wcmwf:reviewTask" >
<assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
              <actor>#{bpm_assignees.get(wcmwf_approveCnt)}</actor>
</assignment>

<event type="task-assign">
<script>
if (wcmwf_reviewCycle > 1)
taskInstance.description = taskInstance.description + " (" + wcmwf_reviewCycle + ")";
</script>


<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<runas>admin</runas>
<script>
<variable name="bpm_assignees" access="read" />
<variable name="wcmwf_approveCnt" access="read" />
<expression>
var current_assignee = bpm_assignees.get(wcmwf_approveCnt);
var emailAddress = current_assignee.properties.email;
var mail = actions.create("mail");
mail.parameters.to = emailAddress;
mail.parameters.subject = "New Alfresco workflow submission: " + wcmwf_label + " by " + person.properties.userName;
mail.parameters.from = person.properties.email;
mail.parameters.text = "Dear " + ":\u000D" + person.properties.firstName + " " + person.properties.lastName + " has submitted the following content in Alfresco for your approval:\u000D" + bpm_workflowDescription;
mail.execute(bpm_package);
</expression>
</script>
</action>

</event>
</task>

<transition name="approve" to="submitserialreview">
<script>
<variable name="wcmwf_approveCnt" access="read, write"/>
<expression>
wcmwf_approveCnt = wcmwf_approveCnt + 1;
</expression>
</script>
</transition>
<transition name="reject" to="endreview" />
</task-node>


<!– –>
<!– Parallel Review –>
<!– –>

<node name="submitparallelreview">
<action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
<foreach>#{bpm_assignees}</foreach>
<var>reviewer</var>
</action>
<transition name="review" to="parallelreview" />
</node>

<task-node name="parallelreview">
<task name="wcmwf:parallelReviewTask">
<assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
<actor>#{reviewer}</actor>
</assignment>
<event type="task-assign">
<script>
if (wcmwf_reviewCycle > 1)
taskInstance.description = taskInstance.description + " (" + wcmwf_reviewCycle + ")";
</script>
</event>
</task>
<transition name="approve" to="joinparallelreview">
<script>
<variable name="wcmwf_approveCnt" access="read,write" />
<expression>
wcmwf_approveCnt = wcmwf_approveCnt +1;
</expression>
</script>
</transition>
<transition name="reject" to="joinparallelreview" />
</task-node>

<join name="joinparallelreview">
<transition to="endreview" />
</join>


<!– –>
<!– End the Review –>
<!– –>

<decision name="endreview">
<transition name="rejected" to="rejected" />
<transition name="approved" to="onapprove">
<condition>#{wcmwf_approveCnt == wcmwf_reviewerCnt}</condition>
</transition>
</decision>

<task-node name="rejected">
<task name="wcmwf:rejectedTask" swimlane="initiator" >
<event type="task-assign">
<script>
if (wcmwf_reviewCycle > 1)
taskInstance.description = taskInstance.description + " (" + wcmwf_reviewCycle + ")";
</script>
</event>
</task>
<transition name="abort" to="end" />
<transition name="resubmit" to="serialorparallel"> <!– restart review process (next cycle) –>
<script>
<variable name="wcmwf_reviewCycle" access="read,write" />
<expression>
wcmwf_reviewCycle = wcmwf_reviewCycle +1;
</expression>
</script>
</transition>
</task-node>

<decision name="onapprove">
<transition name="launchnow" to="submitted" />
<transition name="launchpending" to="submitpending">
<condition>#{wcmwf_launchDate != null}</condition>
</transition>
</decision>

<task-node name="submitpending" end-tasks="true">
<task name="wcmwf:submitpendingTask" swimlane="initiator">
<event type="task-create">
<script>
taskInstance.dueDate = wcmwf_launchDate;
</script>
</event>
<timer duedate="#{wcmwf_launchDate}" transition="launch" >
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script>
logger.log("WCM Submission " + bpm_workflowDescription + " submitted at " + wcmwf_launchDate + " by " + person.properties.userName);
</script>
</action>
</timer>
</task>
<transition name="cancel" to="submitcancelled" />
<transition name="launch" to="submitted" />
</task-node>

<task-node name="submitcancelled">
<task name="wcmwf:submitcancelledTask" swimlane="initiator" />
<transition name="" to="end" />
</task-node>

<task-node name="submitted" end-tasks="true">
<task name="wcmwf:submittedTask" swimlane="initiator">
<timer duedate="5 seconds" transition="onsubmit">
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script>
logger.log("WCM Submit Process: Triggering submit for " + bpm_workflowDescription);
</script>
</action>
</timer>

<event type="task-end">
<script>
<variable name="submitfailed" access="write"/>
<expression>submitfailed = false;</expression>
</script>

<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script>
logger.log("WCM Submit Process: Start submit for " + bpm_workflowDescription + " (by " + person.properties.userName + ")");
</script>
</action>

<action class="org.alfresco.repo.avm.wf.AVMSubmitPackageHandler"/>
<action class="org.alfresco.repo.avm.wf.AVMDeployHandler"/>

<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script>
logger.log("WCM Submit Process: End submit for " + bpm_workflowDescription + " (by " + person.properties.userName + ")");
</script>
</action>
</event>
</task>
<transition name="onsubmit" to="checkfailedsubmit">
<exception-handler>
<script>
<variable name="submitfailed" access="write"/>
<expression>
logger.log("WCM Submit Process: Submit failed for " + bpm_workflowDescription + " (by " + person.properties.userName + ")");
submitfailed = true;
</expression>
</script>
</exception-handler>
</transition>
</task-node>

<decision name="checkfailedsubmit">
<transition name="failure" to="submitfailed">
<condition>#{submitfailed == true}</condition>
</transition>
<transition name="success" to="end">
<condition>#{submitfailed == false}</condition>
</transition>
</decision>

<task-node name="submitfailed">
<task name="wcmwf:submitfailedTask" swimlane="initiator"/>
<transition name="" to="end"/>
</task-node>

<!– –>
<!– End the Process –>
<!– –>

<end-state name="end"/>

<event type="process-end">
<action class="org.alfresco.repo.avm.wf.AVMRemoveAllSrcWebappsHandler"/>
<action class="org.alfresco.repo.avm.wf.AVMReleaseTestServerHandler"/>
<action class="org.alfresco.repo.avm.wf.AVMRemoveWFStoreHandler"/>
</event>

</process-definition>

hanoul
Champ in-the-making
Champ in-the-making
Hi JayJay,

I tried your first posting and got an error saying emailedAssignee.properties is not defined.
I tried the code in your second posting and got the following error:


javax.faces.FacesException: Error calling action method of component with id dialog:finish-button
caused by:
javax.faces.el.EvaluationException: Exception while invoking expression #{DialogManager.finish}
caused by:
org.alfresco.error.AlfrescoRuntimeException: Failed to submit to workflow
caused by:
org.alfresco.service.cmr.workflow.WorkflowException: Failed to signal transition 'null' from workflow task 'jbpm$256'
caused by:
org.jbpm.graph.def.DelegationException: Failed to execute supplied script: ReferenceError: "wcmwf_label" is not defined. (AlfrescoJS#1)
caused by:
org.jbpm.graph.def.DelegationException: Failed to execute supplied script: ReferenceError: "wcmwf_label" is not defined. (AlfrescoJS#1)
caused by:
org.alfresco.scripts.ScriptException: Failed to execute supplied script: ReferenceError: "wcmwf_label" is not defined. (AlfrescoJS#1)
caused by:
org.alfresco.error.AlfrescoRuntimeException: ReferenceError: "wcmwf_label" is not defined. (AlfrescoJS#1)
caused by:
org.mozilla.javascript.EcmaError: ReferenceError: "wcmwf_label" is not defined. (AlfrescoJS#1)


I have no idea where "wcmwf_label" is coming from.

dlsap
Champ in-the-making
Champ in-the-making
hi.  i am having the same problem.  has this been solved yet?  any help would be great.  thanks

pp20218
Champ in-the-making
Champ in-the-making
Hi,

I too have the same problem.Can anyone help me pls?

Thanks