AnsweredAssumed Answered

Workflow Javascript Mail Fail

Question asked by nunuts on May 2, 2012
Latest reply on Jun 27, 2012 by checco
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

Outcomes