cancel
Showing results for 
Search instead for 
Did you mean: 

Sending Email notification to all without loop

quasar
Champ in-the-making
Champ in-the-making
Hi all!
I've added some email notification functionality to WEB-INF\classes\alfresco\workflow\parallelreview_processdefinition.xml
This works fine with a few assignees but if the number of assignees is more than 10 this loop slows down significantly. I've got an idea which is to collect all the email addresses into one string e.g. address1@dd.com, address2@dd.com, address3@dd.com and use it here in the script: mail.parameters.to = address1@dd.com, address2@dd.com, address3@dd.com;
How can I implement this?
Thanks in advance!

My process definitions is here:

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

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

    <swimlane name="initiator" />

    <start-state name="start">
        <task name="wf:submitParallelReviewTask" swimlane="initiator" />
        <transition name="" to="startreview"/>
    </start-state>

    <node name="startreview">
        <action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
            <foreach>#{bpm_assignees}</foreach>
            <var>reviewer</var>
        </action>
        <transition name="" to="review">
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <runas>admin</runas>
                <script>
                        var mail = actions.create("mail");
                        mail.parameters.to = reviewer.properties.email;
                        mail.parameters.subject = "Новая задача в системе Alfresco:" + bpm_workflowDescription;
                        mail.parameters.from = initiator.properties.email;
                        mail.parameters.text = "У вас новая задача от:" + initiator.properties.firstName + " " + initiator.properties.lastName + "! Войдите в систему по адресу http://172.172.174.100/alfresco/";
                        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="reject" to="endreview" />
        <transition name="approve" to="endreview">
            <script>
                <variable name="wf_approveCount" access="read,write" />
                <expression>
                    wf_approveCount = wf_approveCount +1;
                 </expression>
            </script>
        </transition>
    </task-node>

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

    <decision name="isapproved">
        <event type="node-enter">
           <script>
              <variable name="wf_reviewerCount" access="write"/>
              <variable name="wf_requiredPercent" access="write"/>
              <variable name="wf_actualPercent" access="write"/>
              <expression>
                  wf_requiredPercent = wf_requiredApprovePercent;
                  wf_reviewerCount = bpm_assignees.size();
                  wf_actualPercent = ((wf_approveCount * 100) / wf_reviewerCount);
              </expression>
           </script>
        </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>
5 REPLIES 5

quasar
Champ in-the-making
Champ in-the-making
Are there any ideas? Actually there is no any scripting manuals.

msvoren
Champ in-the-making
Champ in-the-making
Not sure what you trying to do here, but i guess you assign a task to a group of people. So, you can loop that group in js and send email to each one of them.
Here's an example:

      var gr_members = people.getMembers(group);
      for (var i=0; i < gr_members.length; i++ )
      {
         var mail = actions.create("mail");
         mail.parameters.to = gr_members[i].properties.email;
         mail.parameters.subject = subject;
         mail.parameters.from = "alfresco";
         mail.parameters.text = "Document is waiting for your response on Alfresco";
         mail.execute(bpm_package);
         logger.log("Email was sent to " + gr_members[i].properties.userName + ".");
      }

quasar
Champ in-the-making
Champ in-the-making
Thank you for your answer! But I'm doing the same thing you described. This approach is very slow if the number of people in group more than 10! I want to collect all email addresses into one string by looping thru bpm_assignees and then send email once only. This should be much faster than sending email to every person. I'm wondering how to implement it. Any ideas?

mrogers
Star Contributor
Star Contributor
The mail action can send to a list of people.     Have a look at the code for the MailActionExecutor for the properties to set, from memory its something like SEND_MANY.

quasar
Champ in-the-making
Champ in-the-making
Thank you!
I've found the MailActionExecuter class but there're no any examples.
Could you post snippets of code?