AnsweredAssumed Answered

Email initiator on approval/rejection

Question asked by ph73nt on Jan 17, 2011
Dear list

I've been struggling to implement email notifications for approval/rejections in workflows. Using similar code to this thread: http://forums.alfresco.com/en/viewtopic.php?f=34&t=24964 I have reproduced the trivial ability to email groupees on a group review task assignment. What I also need is the ability to email the initiator when all groupees have responded, with an accept/reject email. Here is the code that does not work (which only attempts to notify for approval):

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

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

    <swimlane name="initiator"></swimlane>

    <start-state name="start">
        <task name="wf:submitGroupReviewTask" swimlane="initiator" />
        <transition name="" to="startreview">
          <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
              var all_members = people.getMembers(bpm_groupAssignee);

              for(var i=0; i &lt; all_members.length; i++ )
              {
                 var mail = actions.create("mail");
                 mail.parameters.to = all_members[i].properties.email;
                 mail.parameters.subject = "Document for approval";
                 mail.parameters.from = "neil.thomson@ekht.nhs.uk";
                 mail.parameters.text = initiator.properties.firstName + " "
                           + initiator.properties.lastName
                           + " has requested a document review: "
                           + "\u000D\u000D"
                           + bpm_workflowDescription
                           + "\u000D\u000D"
                           + "Log on to Alfresco here: http://10.136.1.176:8080/share";
                 mail.execute(bpm_package);
              }
            </script>
          </action>
        </transition>
    </start-state>

    <node name="startreview">
        <action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
            <foreach>#{people.getMembers(bpm_groupAssignee)}</foreach>
            <var>reviewer</var>
        </action>
        <event type="node-enter">
            <script>
                <variable name="wf_approveCount" access="write" />
                <expression>
                    wf_approveCount = 0;
                </expression>
            </script>
        </event>
        <transition name="review" to="review" />
    </node>

    <task-node name="review">
        <task name="wf:reviewTask">
            <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
               <actor>#{reviewer}</actor>
            </assignment>
            <event type="task-create">
                <script>
                    if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
                    if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
                </script>
            </event>
        </task>
        <transition name="approve" to="endreview">
            <script>
                <variable name="wf_approveCount" access="read,write" />
                <expression>
                    wf_approveCount = wf_approveCount +1;
                 </expression>
            </script>
        </transition>
        <transition name="reject" to="endreview" />
    </task-node>

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

    <decision name="isapproved">
        <event type="node-enter">
           <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
              <script>
                 <variable name="wf_reviewerCount" access="write"/>
                 <expression>people.getMembers(bpm_groupAssignee).length;</expression>
              </script>
           </action>
           <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
              <script>
                 <variable name="wf_requiredPercent" access="write"/>
                 <expression>wf_requiredPercent = wf_requiredApprovePercent;</expression>
              </script>
           </action>
           <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
              <script>
                 <variable name="wf_actualPercent" access="write"/>
                 <expression>wf_actualPercent = ((wf_approveCount * 100) / people.getMembers(bpm_groupAssignee).length);</expression>
              </script>
           </action>
        </event>
        <transition name="reject" to="rejected" />
        <transition name="approve" to="approved">
            <condition>#{wf_actualPercent >= wf_requiredApprovePercent}</condition>
        </transition>
    </decision>
              
    <task-node name="rejected">
        <task name="wf:rejectedParallelTask" swimlane="initiator" />
        <transition to="end" />
    </task-node>

    <task-node name="approved">
        <task name="wf:approvedParallelTask" swimlane="initiator" />
        <transition to="end">
          <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
                 var mail = actions.create("mail");
                 mail.parameters.to = initiator.properties.email;
                 mail.parameters.subject = "A document has been approved";
                 mail.parameters.from = "neil.thomson@ekht.nhs.uk";
                 mail.parameters.text = "The workflow: "
                           + "\u000D\u000D"
                           + bpm_workflowDescription
                           + "\u000D\u000D"
                           + "has been approved."
                           + "\u000D\u000D"
                           + "Log on to Alfresco here: http://10.136.1.176:8080/share";
                 mail.execute(bpm_package);
            </script>
          </action>
        </transition>
    </task-node>

    <end-state name="end"/>

</process-definition>

If somebody could point me in the right direction, I'd really appreciate it.

Many thanks in advance, Neil

Outcomes