我已经在数据列表文件夹上应用了规则,就像在创建每个项目时一样,它应该向各自的人发送电子邮件。
下面是相同的脚本:
function main()
{
var site = siteService.getSite("hardik-test");
var dataListsContainer = site.getContainer("datalists");
var dataLists = dataListsContainer.getChildren();
var fullName, manager,joiningDate;
for(var x=0;x<dataLists.length;x++)
{
var dataList = dataLists[x];
var props = dataList.getProperties();
var title = props["cm:title"];
if(title.equals("Employee"))
{
var dataListItems = dataList.getChildren();
for (var y = 0; y < dataListItems.length; y++)
{
var dataListItem = dataListItems[dataListItems.length-1];
var dataListItemProps = dataListItem.getProperties();
fullName = dataListItemProps["emp:fullName"];
manager = dataListItemProps["emp:manager"];
joiningDate = dataListItemProps["emp:joiningDate"];
}
}
}
// create mail action
var mail = actions.create("mail");
mail.parameters.to = "xyz@xyz.com"; //manager email id should be there
mail.parameters.subject = "Task assigned to you.";
mail.parameters.from = "xyz@xyz.com";
//mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Notify Email Templates/notify_user_email.html.ftl");
mail.parameters.text = "Hi "+manager +"," + "\n A new employee " +fullName +" will be joining our team on "+ joiningDate + "." +
"\n For details, Please click here. \n Regards, \n Administrator" ;
mail.execute(document);
}
每次创建新项目时,脚本都会运行,但在电子邮件中,它不会获取我们输入的最新数据。
如果要使用电子邮件模板,那么如何将参数(自定义值)传递给电子邮件模板?
要创建将重定向到数据列表的链接。
答案 0 :(得分:1)
这是Alfresco信号源具有启发性的许多情况之一。如果您查看MailActionExecuter类,您将看到它定义了几个参数:
public static final String NAME = "mail";
public static final String PARAM_LOCALE = "locale";
public static final String PARAM_TO = "to";
public static final String PARAM_CC = "cc";
public static final String PARAM_BCC = "bcc";
public static final String PARAM_TO_MANY = "to_many";
public static final String PARAM_SUBJECT = "subject";
public static final String PARAM_SUBJECT_PARAMS = "subjectParams";
public static final String PARAM_TEXT = "text";
public static final String PARAM_HTML = "html";
public static final String PARAM_FROM = "from";
public static final String PARAM_FROM_PERSONAL_NAME = "fromPersonalName";
public static final String PARAM_TEMPLATE = "template";
public static final String PARAM_TEMPLATE_MODEL = "template_model";
public static final String PARAM_IGNORE_SEND_FAILURE = "ignore_send_failure";
public static final String PARAM_SEND_AFTER_COMMIT = "send_after_commit";
其中之一是PARAM_TEMPLATE_MODEL,您可以使用“ template_model”进行设置。该参数中的“模型”应该引起您的注意。这意味着您可以使用该参数来传递一组键和值。
稍后,在该类的源代码中,我们看到读取参数的位置,然后将其用于构建完整的模型,然后将其传递给Freemarker模板:
Map<String, Object> suppliedModel = null;
if(ruleAction.getParameterValue(PARAM_TEMPLATE_MODEL) != null)
{
Object m = ruleAction.getParameterValue(PARAM_TEMPLATE_MODEL);
if(m instanceof Map)
{
suppliedModel = (Map<String, Object>)m;
}
else
{
logger.warn("Skipping unsupported email template model parameters of type " + m.getClass().getName() + " : " + m.toString());
}
}
// build the email template model
Map<String, Object> model = createEmailTemplateModel(actionedUponNodeRef, suppliedModel, fromPerson, toRecipients);
因此,如果您在对模板的引用中添加注释,并为操作传递一个附加参数,则假设模板使用了添加到模型中的项目,那么您应该会在结果电子邮件中看到这些项目。
您的代码应类似于:
var templateModel = {};
templateModel["fullName"] = fullName;
templateModel["manager"] = manager;
templateModel["joiningDate"] = joiningDate;
mail.parameters.template_model = templateModel;