cancel
Showing results for 
Search instead for 
Did you mean: 

Workflow Javascript Mail Fail

nunuts
Champ in-the-making
Champ in-the-making
Hi all,
I'm trying to send mail by javascript within workflow. My reference is  http://wiki.alfresco.com/wiki/3.0_JavaScript_API . This is my code :
<?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>
            </event>
         <event type="task-assign">
          <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <expression>
                 var doc1 = userhome.createFile("transform_me1.txt");
                 doc1.mimetype = "text/plain";
                 doc1.content = "This is plain text";
                  var mail = actions.create("mail");
                  mail.parameters.to = "destinationemail.com";
                  mail.parameters.subject = "New Alfresco workflow submission: ";
                  mail.parameters.from = "email.com";
                                           mail.parameters.template = root.childByNamePath("Company Home/Data Dictionary/Email Templates/notify_user_email.ftl");
                  mail.parameters.text = "some text, in case template is not found";           
                  mail.execute(doc1);              
               </expression>
            </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" />
    </task-node>

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

    <end-state name="end" />

</process-definition>
But when I run this code, my workflow is fail. I think the problem is this :
mail.parameters.template = root.childByNamePath("Company Home/Data Dictionary/Email Templates/notify_user_email.ftl");
cause when I remove this line, the workflow works perfectly. Can anyone help me with this?

Thanks
5 REPLIES 5

nunuts
Champ in-the-making
Champ in-the-making
Never mind, i have solved the problem

Thanks

gmce
Confirmed Champ
Confirmed Champ
Can you please explain how you solved this, it's about 2 days i am facing the same problem and can't understand why my workflow refuse to use the mail template addressed by mail.parameters.template

Thanks in advance

checco
Champ in-the-making
Champ in-the-making
Hi Nunuts,
also I'm interested in this issue. Can you share your solution?

Regards,
Francesco

gmce
Confirmed Champ
Confirmed Champ
If you are interested i can post how i solved but i don't know if you have the same problem i encountered.

I have yet to test if my problem was the template with wrong variables or if it was because my alfresco bootstrap in italian language.
Btw here is my workflow code:


if (wf_notifyMe)
                                        {
                                        var mail = actions.create("mail");
                                        var template = "Dizionario dei dati/Modelli di e-mail/Modelli di e-mail di notifica/notify_user_assigned_task_email.ftl";
                                        mail.parameters.to = bpm_assignee.properties.email;
                                        mail.parameters.subject = "Compito:  " + bpm_workflowDescription;
                                        mail.parameters.from = initiator.properties.email;
                                        mail.parameters.template = companyhome.childByNamePath(template);
                                        mail.execute(bpm_package);
                                        }

And here the template:


<html>
   <head>
      <style type="text/css"><!–
      body
      {
         font-family: Arial, sans-serif;
         font-size: 14px;
         color: #4c4c4c;
      }
    
      a, a:visited
      {
         color: #0072cf;
      }
    
      .activity a
      {
         text-decoration: none;
      }
    
      .activity a:hover
      {
         text-decoration: underline;
      }
      –></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: 20px 30px 0px;">
                                 <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                    <tr><td><div style="font-size: 22px; padding-bottom: 4px;">
                                            Nuova attivita' da svolgere
                                          </div><div style="font-size: 14px; margin: 18px 0px 24px 0px; padding-top: 18px; border-top: 1px solid #aaaaaa;">
                                                <div class="activity">
                                                <br></br><br></br>
Attivita' assegnata da ${person.properties.firstName}<#if person.properties.lastName?exists> ${person.properties.lastName}</#if>.
   <br></br>
   <br></br></div>
                                                <div style="font-size: 11px; padding: 4px 0px 12px 0px;">
                                                </div></div></td></tr></table></td></tr><tr>
                              <td><div style="border-top: 1px solid #aaaaaa;"> </div>
                              </td></tr><tr><td style="padding: 0px 30px; font-size: 13px;">
                                 Controlla i tuoi compiti sul tuo pannello di controllo:
<a href="http://xxxxxx.yyyyy.zz:8080/share">Pannello di Controllo di Alfresco Share</a>
                              </td></tr><tr><td><div style="border-bottom: 1px solid #aaaaaa;"> </div>
                              </td></tr><tr><td style="padding: 10px 30px;">
                                 <img src="http://xxxxxx.yyyyy.zz:8080/themes/default/images/logo.png" alt="" width="117" height="48" border="0" />
</td></tr></table></td></tr></table></td></tr></table></body>
</html>

Hope this could help.

checco
Champ in-the-making
Champ in-the-making
Yes, Yours answer is helpful.
Now I can get the template from repository, but I have another question:
Is there any documentation about what model is available in the templete?

That is you use this following line in ftl:
ttivita' assegnata da ${person.properties.firstName}<#if person.properties.lastName?exists> ${person.properties.lastName}</#if>.
But in the process definition you don't set the mail.parameters.template_model variable.

Thanks in advance,
Francesco.