cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with sending group email on assignment

tygerlilyjp
Champ in-the-making
Champ in-the-making
Hi, I'm working on adding email to the current workflows that are stock with Alfresco 3.4d. I understand the basics of how it works, but am unable to get the group workflow to email the assigned group when a task is assigned to a whole group. This is my code for the processdefinition. Would someone give me suggestions on what I need to change, please?


<?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"/>
    </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">
<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 = "New document is waiting";
               mail.parameters.from = "alfresco@indepth.com";
               mail.parameters.text = "Some text";
               mail.execute(bpm_package);
            }
              </script>
              </action>
      </transition> 
    </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" />
    </task-node>

    <end-state name="end"/>

</process-definition>
1 REPLY 1

mitpatoliya
Star Collaborator
Star Collaborator
Your loop and script for sending email looks fine.
You just need to move that logic from the "node" to "task-node".
And under "task-assign" event.
This should work.