Alfresco:电子邮件文档链接到多个人和组

时间:2015-07-28 12:56:10

标签: javascript alfresco alfresco-share alfresco-webscripts

我创建了一个自定义工作流,该工作流将从文档启动,该文档旨在运行电子邮件脚本,以便向收件人发送指向共享中文档的链接。用户可以将文件发送给多个人,组或两者。工作流程启动后工作流程立即结束,这是使用计时器事件实现的(Activiti可以阻止您在没有任何任务的情况下启动和结束工作流程)。

截图

Send Documents Workflow

这适用于电子邮件模板(仅将其发送到DOCUMENT_TEST组,请参阅下面的代码),但我有一些问题:

收件人

我需要将选择人选择组元素转换为 mail.parameters.to_many 方法的可用电子邮件地址。我了解要发送给显示的收件人,我会执行以下操作:

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

我如何循环浏览两个选择元素并编译可用的收件人数组?由于没有任务,我如何在执行中获取这些数据?我最初认为它们是执行变量,但我的方法不起作用(参见.bpmn文件)。

mail.execute()

目前,我的邮件代码执行以下操作:

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

这使用包中的第一个子节点,恰好是附加文档。我认为这是一个草率的工作,特别是因为bpm_package执行速度很慢(平均10-20秒)。如果我只是想引用附加文档的节点,我会使用什么呢? (参见config-custom)

BPMN文件

<?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 = [execution.getVariable("docWorkflow_selectpeople").toString(), execution.getVariable("docWorkflow_selectgroup").toString()];
								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.";

								var document = bpm_package.children[0].nodeRef;
												
								// Execute mail package
								mail.execute(document);]]></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>

模型

<?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>

配置-自定义

<?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>

电子邮件模板

<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;">&nbsp;</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>

0 个答案:

没有答案