11-03-2009 08:27 AM
<transition name="moreInfoNeeded" to="moreInfoNeeded" >
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script>
<variable name="bpm_package" access="read" />
<variable name="initiator" access="read" />
<variable name="bpm_workflowDescription" access="read" />
<expression>
var mail = actions.create("mail");
var prsn = initiator;
try {
var emailAddress = prsn.properties.email;
mail.parameters.to = emailAddress;
mail.parameters.subject = "Content authoring task submitted with additional information";
mail.parameters.from = person.properties.email;
mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/notify_user_email_taskurl.ftl");
mail.parameters.text = "Default text goes here";
mail.execute(bpm_package);
logger.log("send mail to "+ prsn.properties.userName);
} catch (error) {
logger.log("Failed sending mail to "+ prsn.properties.userName + " " + error);
}
</expression>
</script>
</action>
</transition>
Hi,
A new workflow task has been created.
Please got to http://${url.context}/alfresco/command/ui/managetask?id=${pooled.id}&type=${pooled.qnameType}&contai... to view the workflow task.
Regards
Admin
DEBUG [org.alfresco.repo.jscript.ScriptLogger] Failed sending mail to admin ReferenceError: "companyhome" is not defined.
11-10-2009 02:39 AM
Nov 10, 2009 1:04:59 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class org.alfresco.web.app.ContextListener
java.lang.NoClassDefFoundError: org.alfresco.service.cmr.repository.StoreRef
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:63)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:124)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1243)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3787)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:830)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:719)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:615)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Nov 10, 2009 1:04:59 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
Nov 10, 2009 1:05:00 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Nov 10, 2009 1:05:02 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Nov 10, 2009 1:05:02 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
package org.alfresco.repo.action.executer;
import java.io.Serializable;
public class TaskInstanceObject implements Serializable{
/**
*
*/
private static final long serialVersionUID = -5369157359360104619L;
String taskID;
String taskName;
String taskInstanceURL;
public String getTaskID() {
return taskID;
}
public void setTaskID(String taskID) {
this.taskID = taskID;
}
public String getTaskName() {
return taskName;
}
public void setTaskName(String taskName) {
this.taskName = taskName;
}
public String getTaskInstanceURL() {
return taskInstanceURL;
}
public void setTaskInstanceURL(String taskInstanceURL) {
this.taskInstanceURL = taskInstanceURL;
}
}
11-10-2009 03:22 AM
final Action mailAction = actionService.createAction(AttachmentEmailerActionExecuter.NAME);
mailAction.setParameterValue(AttachmentEmailerActionExecuter.PARAM_SUBJECT, properties.get(MailProperty.SUBJECT));
mailAction.setParameterValue(AttachmentEmailerActionExecuter.PARAM_TO, properties.get(MailProperty.TO_ADDRESS));
mailAction.setParameterValue(AttachmentEmailerActionExecuter.PARAM_FROM, properties.get(MailProperty.FROM_ADDRESS));
mailAction.setParameterValue(AttachmentEmailerActionExecuter.PARAM_TEXT, properties.get(MailProperty.BODY));
mailAction.setParameterValue(AttachmentEmailerActionExecuter.PARAM_TEMPLATE, properties.get(MailProperty.TEMPLATE));
mailAction.setParameterValue(AttachmentEmailerActionExecuter.PARAM_ATTACHMENTS, attachments);
mailAction.setParameterValue(AttachmentEmailerActionExecuter.PARAM_MODEL, model);
actionService.executeAction(mailAction, null);
public class SendExternalConfirmation extends JBPMSpringActionHandler {
private static final Logger logger = Logger.getLogger(SendExternalConfirmation.class);
private static final long serialVersionUID = 343656888342953693L;
private static final String INITIATOR_EMAIL_PROCESS_VARIABLE = "initiatorEmail";
private static final String ATTACHMENT_NODEREF_PROCESS_VARIABLE = "a_nodeRef";
//—————————————————
//Public methods
//—————————————————
public void execute(final ExecutionContext context) throws Exception {
final String initiatorEmail = (String) context.getVariable(INITIATOR_EMAIL_PROCESS_VARIABLE);
final JBPMNode attachmentNode = (JBPMNode)context.getVariable(ATTACHMENT_NODEREF_PROCESS_VARIABLE);
final ArrayList<NodeRef> attachedDocuments = new ArrayList<NodeRef>();
attachedDocuments.add(attachmentNode.getNodeRef());
final Action mailAction = actionService.createAction(AttachmentEmailerActionExecuter.NAME);
mailAction.setParameterValue(AttachmentEmailerActionExecuter.PARAM_SUBJECT, "Test subject"));
mailAction.setParameterValue(AttachmentEmailerActionExecuter.PARAM_TO, initiatorEmail);
mailAction.setParameterValue(AttachmentEmailerActionExecuter.PARAM_FROM, "noreply@alfresco.com");
mailAction.setParameterValue(AttachmentEmailerActionExecuter.PARAM_TEXT, "bla bla");
mailAction.setParameterValue(AttachmentEmailerActionExecuter.PARAM_TEMPLATE, "if use freemarker put a template here…");
mailAction.setParameterValue(AttachmentEmailerActionExecuter.PARAM_ATTACHMENTS, attachedDocuments);
mailAction.setParameterValue(TransmittalAttachmentEmailerActionExecuter.PARAM_MODEL, model);
actionService.executeAction(mailAction, null);
}
}
<event type="node-enter">
<action class="com.mycompany.SendExternalConfirmation"/>
</event>
Of course the attachments and email address must have been set in the workflow previously for this to work.11-11-2009 03:51 AM
05-24-2011 05:52 AM
<task name="wf:submitAdhocTask" swimlane="initiator"/>
<event type="task-create">
<script>
<variable name="myTaskId" access="read,write" />
<expression>myTaskId = "jbpm$"+ (executionContext.getTaskInstance().getId()+1);</expression>
</script>
</event>
<transition name="" to="adhoc">
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script>
if(logger.log != null)
logger.log("Testing mail!!!");
var mailAction = actions.create("mail");
mailAction.parameters.from = initiator.properties["cm:email"];
mailAction.parameters.to = bpm_assignee.properties["cm:email"];
mailAction.parameters.subject = person.properties.firstName +" "+person.properties.lastName+" has assigned you this task: " + bpm_workflowDescription;
mailAction.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Notify Email Templates/custom_notify_user_email.ftl");
length = bpm_package.children.length;
mailAction.parameters.taskid = myTaskId;
if(logger.log != null)
{
logger.log(mailAction.parameters.from);
logger.log(mailAction.parameters.to);
logger.log(mailAction.parameters.subject);
logger.log("first name "+person.properties.firstName);
logger.log("last name "+person.properties.lastName);
logger.log(length);
if(length==0)
logger.log("No Document is selected hence email is not sent.");
}
for(var i = 0; i < length; i++)
{
if(logger.log != null)
logger.log("Before Execute");
mailAction.execute(bpm_package.children[i]);
if(logger.log != null)
logger.log("After Execute");
}
</script>
</action>
</transition>
And I have extended the MailActionExecuter.javapublic static class TaskHelper
{
String taskId;
public String getTaskId()
{
return this.taskId;
}
public void setTaskId(String taskId)
{
this.taskId = taskId;
}
}
private Map<String, Object> createEmailTemplateModel(NodeRef ref)
{
Map<String, Object> model = new HashMap<String, Object>(8, 1.0f);
NodeRef person = personService.getPerson(authService.getCurrentUserName());
model.put("person", new TemplateNode(person, serviceRegistry, null));
model.put("document", new TemplateNode(ref, serviceRegistry, null));
NodeRef parent = serviceRegistry.getNodeService().getPrimaryParent(ref).getParentRef();
model.put("space", new TemplateNode(parent, serviceRegistry, null));
// current date/time is useful to have and isn't supplied by FreeMarker by default
model.put("date", new Date());
// add custom method objects
model.put("hasAspect", new HasAspectMethod());
model.put("message", new I18NMessageMethod());
model.put("dateCompare", new DateCompareMethod());
model.put("url", new URLHelper(repoRemoteUrl));
model.put("task", new TaskHelper());
return model;
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.