AnsweredAssumed Answered

Emailing document link to multiple users or groups workflow

Question asked by alangeorge on Jul 29, 2015
Latest reply on May 25, 2017 by prasobhraj
The following is a lot, but any help is much appreciated:

I have created a custom workflow that is to be started from a document, which is designed to run an email script to send the recipients a link to the document in share. Users can send the file to multiple people, groups, or both. The workflow immediately ends after the workflow is started, which is achieved using the timer event (Activiti prevents you from starting and ending a workflow without any tasks from my experience).

This works with the email template (only sends it to the DOCUMENT_TEST group, see code below), but I have some issues:

<strong>Recipients</strong>

I need to convert the Select People and Select Group elements into usable email addresses for the mail.parameters.to_many method. I understand that to send to the shown recipients, I'd do the following:

mail.parameters.to_many = ['ageorge', 'GROUP_DOCUMENT_TEST'];


How would I go about looping through the two selection elements and compiling a usable array of recipients? In other workflows, I'd get the local task variables and use them from there. But since there are no tasks, how would I obtain this data in the execution?

<strong>mail.execute()</strong>

Currently, my mail code executes the following:

mail.execute(bpm_package.children[0].nodeRef);


This uses the first child node in the package, which happens to be the attached document. I think this is a sloppy work around, especially since bpm_package is so slow to execute (10-20 seconds on average). If I just wanted to reference the attached document's node, what would I use instead? (See config-custom)

<strong>BPMN definition</strong>

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="docWorkflow" isExecutable="true">
    <startEvent id="start" activiti:initiator="initiatorUserName" activiti:formKey="docWorkflow:start">
      <extensionElements>
         <activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
            <activiti:field name="script">
               <activiti:string><![CDATA[/*Script to set execution variables here*/]]></activiti:string>
            </activiti:field>
         </activiti:executionListener>
         <activiti:executionListener event="end" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
            <activiti:field name="script">
               <activiti:string><![CDATA[var mail = actions.create("mail");
                        mail.parameters.to_many = GROUP_DOCUMENT_TEST;
                        mail.parameters.subject = "Alfresco: " + person.properties.firstName + " " + person.properties.lastName + " has sent you an item";
                        mail.parameters.from = "alfresco-noReply@cdotech.com";
                        mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Send Document Notification/send_document_notification.html.ftl");
                        mail.parameters.text = "The email template failed to load. Please contact the Alfresco administrator.";

                        // Execute mail package
                        mail.execute(bpm_package.children[0].nodeRef);]]></activiti:string>
            </activiti:field>
         </activiti:executionListener>
      </extensionElements>
   </startEvent>
    <sequenceFlow id="sequenceFlow1" sourceRef="start" targetRef="intermediateEvent1"></sequenceFlow>
    <intermediateCatchEvent id="intermediateEvent1" name="Delay step">
      <timerEventDefinition>
        <timeDuration>PT1S</timeDuration>
      </timerEventDefinition>
    </intermediateCatchEvent>
    <endEvent id="end">
   </endEvent>
    <sequenceFlow id="sequenceFlow2" sourceRef="intermediateEvent1" targetRef="end"></sequenceFlow>
  </process>
</definitions>


<strong>Model</strong>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model xmlns="http://www.alfresco.org/model/dictionary/1.0" name="docWorkflow:model">
    <imports>
        <import prefix="d" uri="http://www.alfresco.org/model/dictionary/1.0'/>
        <import prefix="cm" uri="http://www.alfresco.org/model/content/1.0'/>
        <import prefix="bpm" uri="http://www.alfresco.org/model/bpm/1.0'/>
    </imports>
    <namespaces>
        <namespace prefix="docWorkflow" uri="http://www.alfresco.org/model/dynamic-workflow/docWorkflow/1.0'/>
    </namespaces>
    <types>
        <type name="docWorkflow:start">
            <parent>bpm:startTask</parent>
         <mandatory-aspects>
                <aspect>docWorkflow:selectpeople</aspect>
                <aspect>docWorkflow:selectgroup</aspect>
            </mandatory-aspects>
        </type>
    </types>
   <aspects>
      <aspect name="docWorkflow:selectpeople">
         <associations>
            <association name="docWorkflow:selectpeople">
               <title>Select People</title>
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:person</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </aspect>
      <aspect name="docWorkflow:selectgroup">
         <associations>
            <association name="docWorkflow:selectgroup">
               <title>Select Group(s)</title>
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:authorityContainer</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </aspect>
   </aspects>
</model>


<strong>Config Custom</strong>

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<alfresco-configuration>
    <config condition="docWorkflow:start" evaluator="task-type">
        <forms>
            <form>
                <field-visibility>
                    <show id="docWorkflow:selectpeople"/>
                    <show id="docWorkflow:selectgroup"/>
                    <show id="packageItems"/>
                    <show id="transitions"/>
                </field-visibility>
                <appearance>
                    <set appearance="title" label-id="Recipients" id="info"/>
                    <field set="info" label-id="Select People" id="docWorkflow:selectpeople"/>
               <field set="info" label-id="Select Group(s)" id="docWorkflow:selectgroup"/>
                    <set appearance="title" label-id="Document(s)" id="documents"/>
                    <field set="documents" label-id="Files" id="packageItems"/>
                    <set id="response"/>
                    <field set="response" id="transitions"/>
                </appearance>
            </form>
        </forms>
    </config>   
    <config condition="activiti$docWorkflow" evaluator="string-compare">
        <forms>
            <form>
                <field-visibility>
                    <show id="docWorkflow:selectpeople"/>
                    <show id="docWorkflow:selectgroup"/>
                    <show id="packageItems"/>
                    <show id="transitions"/>
                </field-visibility>
                <appearance>
                    <set appearance="title" label-id="Recipients" id="info"/>
                    <field set="info" label-id="Select People" id="docWorkflow:selectpeople"/>
               <field set="info" label-id="Select Group(s)" id="docWorkflow:selectgroup"/>
                    <set appearance="title" label-id="Document(s)" id="documents"/>
                    <field set="documents" label-id="Files" id="packageItems"/>
                    <set id="response"/>
                    <field set="response" id="transitions"/>
                </appearance>
            </form>
        </forms>
    </config>
</alfresco-configuration>


<strong>Email Tempalte</strong>

<html>
   <head>
      <style type="text/css"><!–
      body
      {
         font-family: Arial, sans-serif;
         font-size: 14px;
         color: #4c4c4c;
      }
     
      a, a:visited
      {
         color: #0072cf;
      }
      –></style>
   </head>
  
   <body bgcolor="#dddddd">
      <table width="100%" cellpadding="20" cellspacing="0" border="0" bgcolor="#dddddd">
         <tr>
            <td width="100%" align="center">
               <table width="70%" cellpadding="0" cellspacing="0" bgcolor="white" style="background-color: white; border: 1px solid #aaaaaa;">
                  <tr>
                     <td width="100%">
                        <table width="100%" cellpadding="0" cellspacing="0" border="0">
                           <tr>
                              <td style="padding: 10px 30px 0px;">
                                 <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                    <tr>
                                       <td>
                                          <table cellpadding="0" cellspacing="0" border="0">
                                             <tr>
                                                <td>
                                                   <img src="${shareUrl}/res/components/images/page-64.png" alt="" width="64" height="64" border="0" style="padding-right: 20px;" />
                                                </td>
                                                <td>
                                                   <div style="font-size: 22px; padding-bottom: 4px;">
                                                      ${person.properties.firstName} <#if person.properties.lastName?exists> ${person.properties.lastName}</#if> has sent you a new content item, ${document.name}, in the ${document.siteShortName!""} site
                                                   </div>
                                                   <div style="font-size: 13px;">
                                                      ${date?datetime?string.full}
                                                   </div>
                                                </td>
                                             </tr>
                                          </table>
                                          <div style="font-size: 14px; margin: 12px 0px 24px 0px; padding-top: 10px; border-top: 1px solid #aaaaaa;">
                                             <p>Hi,</p>

                                             <p>${person.properties.firstName}
                                             <#if person.properties.lastName?exists> ${person.properties.lastName}</#if>
                                             has sent you a new content item, ${document.name}, in the ${document.siteShortName!""} site.

                                             <p>Click this link to view the item:<br />
                                             <br />${document.shareUrl}</p>
                                            
                                             <p>Sincerely,<br />
                                             Alfresco</p>
                                          </div>
                                       </td>
                                    </tr>
                                 </table>
                              </td>
                           </tr>
                           <tr>
                              <td>
                                 <div style="border-bottom: 1px solid #aaaaaa;"> </div>
                              </td>
                           </tr>
                           <tr>
                              <td style="padding: 10px 30px;">
                                 <img src="${shareUrl}/themes/default/images/app-logo.png" alt="" width="117" height="48" border="0" />
                              </td>
                           </tr>
                        </table>
                     </td>
                  </tr>
               </table>
            </td>
         </tr>
      </table>
   </body>
</html>

Attachments

Outcomes