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

ekimnosneb
Champ in-the-making
Champ in-the-making
The following adhoc_processdefinition.xml file (in "/opt/alfresco-3.4.b/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/workflow") works for me:
<?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 class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <actor>#{bpm_assignee}</actor>
      </assignment>
   </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>
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <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.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Notify Email Templates/notify_user_assigned_task_email.ftl");
               mail.parameters.text = "A task was created.";
               mail.execute(bpm_package);
               }
      </script>
            </action>
         </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.email;
                 mail.parameters.subject = "Adhoc Task: " + bpm_workflowDescription;
                 mail.parameters.from = bpm_assignee.properties.email;
    mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Notify Email Templates/notify_initiator_completed_task_email.ftl");
                 mail.parameters.text = "This task is 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"/>
  
</process-definition>
NOTE: I am using Email templates for both the initial notification and the "Task Done" notification.
Also note that you need to use the http://wiki.alfresco.com/wiki/Workflow_Console to "deploy" any changes to the workflow definition.

efestione
Champ in-the-making
Champ in-the-making
NOTE: I am using Email templates for both the initial notification and the "Task Done" notification.
Also note that you need to use the http://wiki.alfresco.com/wiki/Workflow_Console to "deploy" any changes to the workflow definition.

Hi ekimnosneb,
could you please share your email notification template (if they contain various reference to the started workflow) or suggest me a good point of start?

I am trying to write a comprehensive notification email…

Thanks

ekimnosneb
Champ in-the-making
Champ in-the-making
NOTE: I am using Email templates for both the initial notification and the "Task Done" notification.
Also note that you need to use the http://wiki.alfresco.com/wiki/Workflow_Console to "deploy" any changes to the workflow definition.

Hi ekimnosneb,
could you please share your email notification template (if they contain various reference to the started workflow) or suggest me a good point of start?

I am trying to write a comprehensive notification email…

Thanks
If I remember correctly, I used the invite-email.ftl template (in Share: Repository> Data Dictionary> Email Templates> invite) as an example and created my own in a new folder (in Share: Repository> Data Dictionary> Email Templates> Notify Email Templates).  Of course, make sure you use the correct path in the adhoc_processdefinition.xml file.

notify_user_assigned_task_email.ftl:
A new task was assigned to you by ${person.properties.firstName}<#if person.properties.lastName?exists> ${person.properties.lastName}</#if>.

Check the My Tasks dashlet on your dashboard:
${url.serverPath}/share

Regards

Alfresco

notify_initiator_completed_task_email.ftl:
A task you assigned to ${person.properties.firstName}<#if person.properties.lastName?exists> ${person.properties.lastName}</#if> is done.

Check the Workflows I've Started page on your dashboard:
${url.serverPath}/share/page/my-workflows

Regards

Alfresco

efestione
Champ in-the-making
Champ in-the-making
Thank you very much.

I will try to extract task properties too…

jollymon
Champ in-the-making
Champ in-the-making
Great Tutorial!

I had a question on expanding this for additional workflows as well. The review and approve is the most common workflow we use but I need to know how to have the email sent back to the workflow initiator in this script. I tried a few things and must have some syntax error.
<?xml version="1.0" encoding="UTF-8"?>

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

    <swimlane name="initiator" />

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

    <swimlane name="reviewer">
        <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
            <actor>#{bpm_assignee}</actor>
        </assignment>   
    </swimlane>

    <task-node name="review">
        <task name="wf:reviewTask" swimlane="reviewer">
            <event type="task-create">
                <script>
                    if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
                    if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
                </script>
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
                  {
               var mail = actions.create("mail");
               mail.parameters.to = bpm_assignee.properties.email;
               mail.parameters.subject = "Review and Approve: " + bpm_workflowDescription;
               mail.parameters.from = initiator.properties.email;
               mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Notify Email Templates/notify_user_assigned_task_email.ftl");
               mail.parameters.text = "A task was created.";
               mail.execute(bpm_package);
               }
      </script>
            </action>
            </event>
        </task>
        <transition name="approve" to="approved" />
        <transition name="reject" to="rejected" />
    </task-node>

    <task-node name="rejected">
        <task name="wf:rejectedTask" swimlane="initiator" />
        <transition name="" to="end" />
                  <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 = "Review Task: " + bpm_workflowDescription;
                 mail.parameters.from = bpm_assignee.properties.email;
             mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Notify Email Templates/notify_initiator_completed_task_email.ftl");
                 mail.parameters.text = "This task is done.";
                 mail.execute(bpm_package);
              }
           </script>
         </action>
      </transition>
   </task-node>

    <task-node name="approved">
        <task name="wf:approvedTask" swimlane="initiator" />
        <transition name="" to="end" />
                <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 = "Review Task: " + bpm_workflowDescription;
                 mail.parameters.from = bpm_assignee.properties.email;
       mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Notify Email Templates/notify_initiator_completed_task_email.ftl");
                 mail.parameters.text = "This task is done.";
                 mail.execute(bpm_package);
              }
           </script>
         </action>
      </transition>
   </task-node>

    <end-state name="end" />

</process-definition>

I have ran the deploy and can get the initial notificaton sent out however my attempt at the approve/ reject code must be flawed  Smiley Surprised

amitabhandari1
Champ in-the-making
Champ in-the-making
hi jollymon,

Please make the highlighted changes: basically removed "/" from end tag .It means you are closing transition . although you have to first run the script  and then close the transition

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

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

        <swimlane name="initiator" />

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

        <swimlane name="reviewer">
            <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
                <actor>#{bpm_assignee}</actor>
            </assignment>  
        </swimlane>

        <task-node name="review">
            <task name="wf:reviewTask" swimlane="reviewer">
                <event type="task-create">
                    <script>
                        if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
                        if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
                    </script>
                <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <script>
                      {
                   var mail = actions.create("mail");
                   mail.parameters.to = bpm_assignee.properties.email;
                   mail.parameters.subject = "Review and Approve: " + bpm_workflowDescription;
                   mail.parameters.from = initiator.properties.email;
                   mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Notify Email Templates/notify_user_assigned_task_email.ftl");
                   mail.parameters.text = "A task was created.";
                   mail.execute(bpm_package);
                   }
          </script>
                </action>
                </event>
            </task>
            <transition name="approve" to="approved" />
            <transition name="reject" to="rejected" />
        </task-node>

        <task-node name="rejected">
            <task name="wf:rejectedTask" swimlane="initiator" />
                 <transition name="" to="end" />    Change it to            <transition name="" to="end" > 
                      <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 = "Review Task: " + bpm_workflowDescription;
                     mail.parameters.from = bpm_assignee.properties.email;
                 mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Notify Email Templates/notify_initiator_completed_task_email.ftl");
                     mail.parameters.text = "This task is done.";
                     mail.execute(bpm_package);
                  }
               </script>
             </action>
          </transition>
       </task-node>

        <task-node name="approved">
            <task name="wf:approvedTask" swimlane="initiator" />
            <transition name="" to="end" />    Change it to            <transition name="" to="end" > 
                    <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 = "Review Task: " + bpm_workflowDescription;
                     mail.parameters.from = bpm_assignee.properties.email;
           mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Notify Email Templates/notify_initiator_completed_task_email.ftl");
                     mail.parameters.text = "This task is done.";
                     mail.execute(bpm_package);
                  }
               </script>
             </action>
          </transition>
       </task-node>

        <end-state name="end" />

    </process-definition>

jollymon
Champ in-the-making
Champ in-the-making
Thank you so much! I will post back my findings and copy my code for all my email workflow notifiers, maybe they can fold this into alfresco at some point. It would be a great option to have a checkbox when creating workflows that allowed for email notifications.

winterrobot
Champ in-the-making
Champ in-the-making
Hello - I am in the process of implementing email notificaiton for Review and approve workflows.

I am using the following processdefinition.xml code but am getting the following error when assigning a task using this workflow

Workflow could not be started {0}
org.alfresco.service.cmr.workflow.WorkflowException: 08215982 Failed to signal transition null from workflow task jbpm$505.

Can anyone please shed some light on this? Any help would be really appreciated!!

Many thanks in advance


–>


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

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

    <swimlane name="initiator" />

    <start-state name="start">
    <task name="wf:submitReviewTask" swimlane="initiator" />
    <transition name="" to="review">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
        <runas>admin</runas>
        <script>
          <!– Send a notification email to the reviewer –>
          var mail = actions.create("mail");
          mail.parameters.to = bpm_assignee.properties.email;
          mail.parameters.subject = "new Review Task";
          mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Notify Email Templates/notify_user_email.ftl"
          mail.parameters.text = "A document awaiting your approval at Alfresco";
          mail.execute(bpm_package.children[0]);</script>
      </action>
    </transition>
  </start-state>

    <swimlane name="reviewer">
        <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
            <actor>#{bpm_assignee}</actor>
        </assignment>   
    </swimlane>

    <task-node name="review">
        <task name="wf:reviewTask" swimlane="reviewer">
            <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="approve" to="approved" />
        <transition name="reject" to="rejected" />
    </task-node>

    <task-node name="rejected">
        <task name="wf:rejectedTask" swimlane="initiator" />
        <transition name="" to="end" />
    </task-node>

    <task-node name="approved">
        <task name="wf:approvedTask" swimlane="initiator" />
        <transition name="" to="end" />
    </task-node>

    <end-state name="end" />

</process-definition>