cancel
Showing results for 
Search instead for 
Did you mean: 

Adhoc Task Workflow Wizard Email

samjeff
Champ in-the-making
Champ in-the-making
Dear all,

I would like  Adhoc Task Workflow Wizard can send email to user who assign to.
How can I do this?
Because in  Adhoc Task Workflow Wizard there is no email notification to the user.
Please help me?
Thank you so much
17 REPLIES 17

mabayona
Champ on-the-rise
Champ on-the-rise
If you look at the wiki doc about advanced workflows you find out a sample on how to send an email notification:

http://wiki.alfresco.com/wiki/WorkflowAdministration

Basically, the notification is sent by the JS code that is executed on a transition.

            var mail = actions.create("mail");
            mail.parameters.to = initiator.properties["cm:email"];
            mail.parameters.subject = "Adhoc Task " + bpm_workflowDescription;
            mail.parameters.from = bpm_assignee.properties["cm:email"];
            mail.parameters.text = "It's done";
            mail.execute(bpm_package);

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

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

  <swimlane name="initiator"/>

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

  <swimlane name="assignee">
    <assignment actor-id="#{bpm_assignee.properties['cm:userName']}"/>
  </swimlane>
  
  <task-node name="adhoc">
    <task name="wf:adhocTask" swimlane="assignee">
      <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="" to="completed">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
        <script>
          if (wf_notifyMe)
          {
            var mail = actions.create("mail");
            mail.parameters.to = initiator.properties["cm:email"];
            mail.parameters.subject = "Adhoc Task " + bpm_workflowDescription;
            mail.parameters.from = bpm_assignee.properties["cm:email"];
            mail.parameters.text = "It's done";
            mail.execute(bpm_package);
          }
        </script>
      </action>
    </transition>
  </task-node>
  
  <task-node name="completed">
    <task name="wf:completedAdhocTask" swimlane="initiator"/>
    <transition name="" to="end"/>
  </task-node>
     
  <end-state name="end"/>

  <event type="process-end">
     <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
        <script>
           if (logger.isLoggingEnabled())
              logger.log("End of process.  Cancelled: " + cancelled);
        </script>
     </action>
  </event>
  
</process-definition>

samjeff
Champ in-the-making
Champ in-the-making
Thank you so much for your tutorial.
I would like to configure something. I want every Ad-Hoc there is an email notify before due date.
For example: Due date: 9 July 2008. Alfresco send email to notify user  3 days before due date on 6 July 2008.
How to setup this?

What transition I must use?
And what script I can use?

Thank you for your help & support

mabayona
Champ on-the-rise
Champ on-the-rise
You can use the following:

-  a timer that triggers three days before due date (as you need)

and

- a transition to same state (this way the workflow remains in same estate).

samjeff
Champ in-the-making
Champ in-the-making
Would you please to tell me the detail code?
I've already made this script but failed, nothing happened:

<task-node name="adhoc">
      <task name="wf:adhocTask" swimlane="assignee">
         <event type="task-create">
            <script>
               if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
               if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
            </script>
         </event>
       <timer duedate="#{wcmwf_launchDate}" transition="launch" >
       <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
          <script>
             logger.log("WCM Submission submitted at " + wcmwf_launchDate);
             var mail = actions.create("mail");
              mail.parameters.to = initiator.properties.email;
              mail.parameters.subject = "Reminder " + bpm_workflowDescription;
              mail.parameters.from = bpm_assignee.properties.email;
              mail.parameters.text = "It is a reminder…";
              mail.execute(bpm_package);
          </script>
       </action>
    </timer>
      </task>
      <transition name="" to="completed">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
           <script>
              if (wf_notifyMe)
              {
                 var mail = actions.create("mail");
                 mail.parameters.to = initiator.properties.email;
                 mail.parameters.subject = "Reminder " + bpm_workflowDescription;
                 mail.parameters.from = bpm_assignee.properties.email;
                 mail.parameters.text = "It's done";
                 mail.execute(bpm_package);
              }
           </script>
         </action>
      </transition>
   </task-node>


Please help me. Thanks so much.

madtechsupport
Champ in-the-making
Champ in-the-making
Hello All,

I have the same requirement as the original poster, but for Alfresco community edition 3.4b.

Where EXACTLY in adhoc_processdefinition.xml should the email code block be inserted to that it actually sends a mail when the task is assigned.  It is not clear to me from this post or any of the documentation that I have found so far, how this should be done.

Any help would be greatly appreciated since this is the last piece of functionality required before deploying alfresco.

With thanks,


Warren.

mthomas
Champ in-the-making
Champ in-the-making
Is there a specific location?  Or can this code just be added somewhere near the top?

mthomas
Champ in-the-making
Champ in-the-making
Figured it out:
Works when place in the start state as below.  Not sure if the runas admin command is needed.

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

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

   <swimlane name="initiator"/>
   <start-state name="start">
      <task name="wf:submitAdhocTask" swimlane="initiator"/>
      <transition name="" to="adhoc">
   <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
   <runas>admin</runas>
           <script>
                 var mail = actions.create("mail");
                 mail.parameters.to = bpm_assignee.properties.email;
                 mail.parameters.subject = "Adhoc Task " + bpm_workflowDescription;
                 mail.parameters.from = initiator.properties.email;
                 mail.parameters.text = "New Adhoc Task";
                 mail.execute(bpm_package);
           </script>
         </action>
      </transition>
   </start-state>

ekimnosneb
Champ in-the-making
Champ in-the-making
Figured it out:
Works when place in the start state as below.  Not sure if the runas admin command is needed.

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

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

   <swimlane name="initiator"/>
   <start-state name="start">
      <task name="wf:submitAdhocTask" swimlane="initiator"/>
      <transition name="" to="adhoc">
   <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
   <runas>admin</runas>
           <script>
                 var mail = actions.create("mail");
                 mail.parameters.to = bpm_assignee.properties.email;
                 mail.parameters.subject = "Adhoc Task " + bpm_workflowDescription;
                 mail.parameters.from = initiator.properties.email;
                 mail.parameters.text = "New Adhoc Task";
                 mail.execute(bpm_package);
           </script>
         </action>
      </transition>
   </start-state>

Unfortunately, the above didn't work for me in the adhoc_processdefinition.xml file of 3.4b.  I received the following error(s) in the catalina.out when restarting and alfresco fails to start completely:
15:04:42,433  ERROR [web.context.ContextLoader] Context initialization failed
org.alfresco.error.AlfrescoRuntimeException: 11190001 Workflow deployment failed
   at org.alfresco.repo.workflow.WorkflowDeployer.init(WorkflowDeployer.java:330)
   at org.alfresco.repo.workflow.WorkflowDeployer$1.doWork(WorkflowDeployer.java:437)
   at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:508)
   at org.alfresco.repo.workflow.WorkflowDeployer.onBootstrap(WorkflowDeployer.java:433)
   at org.springframework.extensions.surf.util.AbstractLifecycleBean.onApplicationEvent(AbstractLifecycleBean.java:56)
   at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
   at org.alfresco.repo.management.SafeApplicationEventMulticaster.multicastEvent(SafeApplicationEventMulticaster.java:78)
   at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:294)
   at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:858)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:419)
   at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:261)
   at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:192)
   at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
   at org.alfresco.web.app.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:63)
   at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
   at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
   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:546)
   at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
   at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
   at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
   at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
   at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
   at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
   at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
   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:519)
   at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
   at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
   at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.alfresco.service.cmr.workflow.WorkflowException: 11190000 Failed to determine if workflow definition  is already deployed.
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.isDefinitionDeployed(JBPMEngine.java:394)
   at org.alfresco.repo.workflow.WorkflowServiceImpl.isDefinitionDeployed(WorkflowServiceImpl.java:210)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:34)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:44)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.audit.AuditMethodInterceptor.proceedWithAudit(AuditMethodInterceptor.java:217)
   at org.alfresco.repo.audit.AuditMethodInterceptor.proceed(AuditMethodInterceptor.java:184)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:137)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy71.isDefinitionDeployed(Unknown Source)
   at org.alfresco.repo.workflow.WorkflowDeployer.init(WorkflowDeployer.java:293)
   … 37 more
Caused by: org.jbpm.JbpmException: Failed to parse process definition from jBPM xml stream.
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.compileProcessDefinition(JBPMEngine.java:1943)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine$2.doInJbpm(JBPMEngine.java:382)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine$2.doInJbpm(JBPMEngine.java:378)
   at org.springmodules.workflow.jbpm31.JbpmTemplate$1.doInHibernate(JbpmTemplate.java:87)
   at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
   at org.springmodules.workflow.jbpm31.JbpmTemplate.execute(JbpmTemplate.java:80)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.isDefinitionDeployed(JBPMEngine.java:377)
   … 58 more
Caused by: org.jbpm.jpdl.JpdlException: [[ERROR] cvc-complex-type.2.4.a: Invalid content was found starting with element 'action'. One of '{"urn:jbpm.org:jpdl-3.1":task, "urn:jbpm.org:jpdl-3.1":transition, "urn:jbpm.org:jpdl-3.1":event, "urn:jbpm.org:jpdl-3.1":exception-handler}' is expected. line 10, [WARNING] swimlane 'initiator' does not have an assignment]
   at org.jbpm.jpdl.xml.JpdlXmlReader.readProcessDefinition(JpdlXmlReader.java:173)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.compileProcessDefinition(JBPMEngine.java:1937)

Are there any other changes necessary to that file?  The Exception seems to indicate it's looking for one of the following instead of the "action": task, transition or event.

mthomas
Champ in-the-making
Champ in-the-making
Not sure why the error.  I too am on 3.4b.  Check your syntax maybe.