cancel
Showing results for 
Search instead for 
Did you mean: 

Using wf-email.htmll template from JS

dranakan
Champ on-the-rise
Champ on-the-rise
Hello,

I want to use the template wf-email.html.ftl but I don't know how to specify the $shareUrl (and other var). How can I define $shareUrl, $productName, …

Code to send the mail with template

  var mail = actions.create("mail");
  mail.parameters.to = "me@custom.ch";
  mail.parameters.subject = "Test template";
var docTemplate = companyhome.childByNamePath("Data Dictionary/Email Templates/Workflow Notification/wf-email.html.ftl");
node = search.findNode("workspace://SpacesStore/de567518-bf00-4a08-9031-434bf8c3d766");
var args=new Array();
args['workflowTitle']="blabla";
mail.parameters.text=node.processTemplate(docTemplate,args);
mail.execute(node);

wf-email.html.ftl

<html>
   <head>
      <style type="text/css"><!–
      body
      {
         font-family: Arial, sans-serif;
         font-size: 14px;
         color: #4c4c4c;
      }
     
      a, a:visited
      {
         color: #0072cf;
      }
      –></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: 10px 30px 0px;">
                                 <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                    <tr>
                                       <td>
                                          <table cellpadding="0" cellspacing="0" border="0">
                                             <tr>
                                                <td>
                                                   <img src="${shareUrl}/res/components/images/task-64.png" alt="" width="64" height="64" border="0" style="padding-right: 20px;" />
                                                </td>
                                                <td>
                                                   <div style="font-size: 22px; padding-bottom: 4px;">
                                                      <#if args.workflowPooled == true>
                                                         New Pooled Task
                                                      <#else>
                                                         You have been assigned a task
                                                      </#if>
                                                   </div>
                                                   <div style="font-size: 13px;">
                                                      ${date?datetime?string.full}
                                                   </div>
                                                </td>
                                             </tr>
                                          </table>
                                          <div style="font-size: 14px; margin: 12px 0px 24px 0px; padding-top: 10px; border-top: 1px solid #aaaaaa;">
                                             <p>Hi,</p>

                                             <p>
                                                <#if args.workflowPooled == true>
                                                   The following pooled task is available to be claimed:
                                                <#else>
                                                   You have been assigned the following task:
                                                </#if>
                                             </p>
                                            
                                             <p><b>"${args.workflowTitle}"</b></p>
                                            
                                             <#if (args.workflowDescription)??>                                            
                                                <p>${args.workflowDescription}</p>                                            
                                             </#if>
                                            
                                             <p>
                                                <#if (args.workflowDueDate)??>Due:  <b>${args.workflowDueDate?date?string.full}</b><br></#if>
                                                <#if (args.workflowPriority)??>
                                                   Priority:  
                                                   <b>
                                                   <#if args.workflowPriority == 3>
                                                      Low
                                                   <#elseif args.workflowPriority == 2>
                                                      Medium
                                                   <#else>
                                                      High
                                                   </#if>
                                                   </b>
                                                </#if>
                                             </p>
                                            
                                             <#if (args.workflowDocuments)??>
                                                <table cellpadding="0" callspacing="0" border="0" bgcolor="#eeeeee" style="padding:10px; border: 1px solid #aaaaaa;">
                                                   <#list args.workflowDocuments as doc>
                                                      <tr>
                                                         <td>
                                                            <table cellpadding="0" cellspacing="0" border="0">
                                                               <tr>
                                                                  <td valign="top">
                                                                     <img src="${shareUrl}/res/components/images/generic-file.png" alt="" width="64" height="64" border="0" style="padding-right: 10px;" />
                                                                  </td>
                                                                  <td>
                                                                     <table cellpadding="2" cellspacing="0" border="0">
                                                                        <tr>
                                                                           <td><b>${doc.name}</b></td>
                                                                        </tr>
                                                                        <tr>
                                                                           <td>Click on this link to download the document:</td>
                                                                        </tr>
                                                                        <tr>
                                                                           <td>
                                                                              <a href="${shareUrl}/proxy/alfresco/api/node/content/workspace/SpacesStore/${doc.id}/${doc.name}?a=true">
                                                                              ${shareUrl}/proxy/alfresco/api/node/content/workspace/SpacesStore/${doc.id}/${doc.name}?a=true</a>
                                                                           </td>
                                                                        </tr>
                                                                     </table>
                                                                  </td>
                                                               </tr>
                                                            </table>
                                                         </td>
                                                      </tr>
                                                      <#if doc_has_next>
                                                         <tr><td><div style="border-top: 1px solid #aaaaaa; margin:12px;"></div></td></tr>
                                                      </#if>
                                                   </#list>
                                                </table>
                                             </#if>
                                            
                                             <#if args.workflowPooled == true>
                                                <p>Click this link to view the task:</p>
                                                <p><a href="${shareUrl}/page/task-details?taskId=${args.workflowId}">${shareUrl}/page/task-details?taskId=${args.workflowId}</a>
                                             <#else>
                                                <p>Click this link to edit the task:</p>
                                                <p><a href="${shareUrl}/page/task-edit?taskId=${args.workflowId}">${shareUrl}/page/task-edit?taskId=${args.workflowId}</a>
                                             </#if>
                                            
                                             <p>Sincerely,<br />
                                             Alfresco ${productName!""}</p>
                                          </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;">
                                 To find out more about Alfresco ${productName!""} visit <a href="http://www.alfresco.com">http://www.alfresco.com</a>
                              </td>
                           </tr>
                           <tr>
                              <td>
                                 <div style="border-bottom: 1px solid #aaaaaa;"> </div>
                              </td>
                           </tr>
                           <tr>
                              <td style="padding: 10px 30px;">
                                 <img src="${shareUrl}/themes/default/images/app-logo.png" alt="" width="117" height="48" border="0" />
                              </td>
                           </tr>
                        </table>
                     </td>
                  </tr>
               </table>
            </td>
         </tr>
      </table>
   </body>
</html>

Error sending the mail :

500 Description:   An error inside the HTTP server which prevented it from fulfilling the request.

Message:   11150065 Wrapped Exception (with status template): 11152208 Failed to execute script 'classpath*:alfresco/templates/webscripts/org/alfresco/module/custom/searchWorkflow/searchWorkflow.get.js': 11152207 Error during processing of the template 'Expression shareUrl is undefined on line 34, column 64 in string://fixed.'. Please contact your system administrator.
   
Exception:   freemarker.core.InvalidReferenceException - Expression shareUrl is undefined on line 34, column 64 in string://fixed.
   
   freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
   freemarker.core.Expression.getStringValue(Expression.java:118)
   freemarker.core.Expression.getStringValue(Expression.java:93)
   freemarker.core.DollarVariable.accept(DollarVariable.java:76)
   freemarker.core.Environment.visit(Environment.java:221)
   freemarker.core.MixedContent.accept(MixedContent.java:92)
   freemarker.core.Environment.visit(Environment.java:221)
   freemarker.core.Environment.process(Environment.java:199)
   freemarker.template.Template.process(Template.java:237)
   org.alfresco.repo.template.FreeMarkerProcessor.processString(FreeMarkerProcessor.java:260)
   org.alfresco.repo.processor.TemplateServiceImpl.processTemplateString(TemplateServiceImpl.java:208)
   org.alfresco.repo.processor.TemplateServiceImpl.processTemplateString(TemplateServiceImpl.java:227)
   sun.reflect.GeneratedMethodAccessor1511.invoke(Unknown Source)
   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   java.lang.reflect.Method.invoke(Method.java:597)
   org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
   org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:34)
   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:44)
   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:146)
   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   $Proxy107.processTemplateString(Unknown Source)
   org.alfresco.repo.jscript.ScriptNode.processTemplate(ScriptNode.java:2623)
   org.alfresco.repo.jscript.ScriptNode.processTemplate(ScriptNode.java:2537)
   sun.reflect.GeneratedMethodAccessor1509.invoke(Unknown Source)
   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   java.lang.reflect.Method.invoke(Method.java:597)
   org.mozilla.javascript.MemberBox.invoke(MemberBox.java:155)
   org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
   org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
   org.mozilla.javascript.gen.c75._c0(file:/opt/alfresco-4.0.b/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/module/custom/searchWorkflow/searchWorkflow.get.js:51)
   org.mozilla.javascript.gen.c75.call(file:/opt/alfresco-4.0.b/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/module/custom/searchWorkflow/searchWorkflow.get.js)
   org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
   org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
   org.mozilla.javascript.gen.c75.call(file:/opt/alfresco-4.0.b/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/module/custom/searchWorkflow/searchWorkflow.get.js)
   org.mozilla.javascript.gen.c75.exec(file:/opt/alfresco-4.0.b/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/module/custom/searchWorkflow/searchWorkflow.get.js)
   org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:483)
   org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:191)
   org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:282)
   org.alfresco.repo.web.scripts.RepositoryScriptProcessor.executeScript(RepositoryScriptProcessor.java:102)
   org.springframework.extensions.webscripts.AbstractWebScript.executeScript(AbstractWebScript.java:1128)
   org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:86)
   org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:400)
   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:388)
   org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:462)
   org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:500)
   org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:316)
   org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:372)
   org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
   org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:58)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:465)
   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
   org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
   org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
   java.lang.Thread.run(Thread.java:619)
   
Exception:   org.alfresco.service.cmr.repository.TemplateException - 11152207 Error during processing of the template 'Expression shareUrl is undefined on line 34, column 64 in string://fixed.'. Please contact your system administrator.
   
   org.alfresco.repo.template.FreeMarkerProcessor.processString(FreeMarkerProcessor.java:270)
   
Exception:   org.alfresco.scripts.ScriptException - 11152208 Failed to execute script 'classpath*:alfresco/templates/webscripts/org/alfresco/module/custom/searchWorkflow/searchWorkflow.get.js': 11152207 Error during processing of the template 'Expression shareUrl is undefined on line 34, column 64 in string://fixed.'. Please contact your system administrator.
   
   org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:195)
   
Exception:   org.springframework.extensions.webscripts.WebScriptException - 11150065 Wrapped Exception (with status template): 11152208 Failed to execute script 'classpath*:alfresco/templates/webscripts/org/alfresco/module/custom/searchWorkflow/searchWorkflow.get.js': 11152207 Error during processing of the template 'Expression shareUrl is undefined on line 34, column 64 in string://fixed.'. Please contact your system administrator.
   
   org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:905)

Related subject

I18 with template : https://forums.alfresco.com/en/viewtopic.php?f=36&t=42051
21 REPLIES 21

anik
Champ in-the-making
Champ in-the-making
Hi All,
As per our previous discussion we came to our conclusion that template_model parameter is not there in Email executor class. So can Anybody help me..to achieve the same functionality in alfresco Enterprise 3.4.7
:shock: ??

Is there any amp file that can be applied to alfresco.war which enables such mandatory feature to 3.4.7 version
or any other safe solution to achieve this.(If this functionality is available with 4.0 and then pls tell me which all file needs to be modified in alfresco 3.4.7 to achieve this)

Please help :?
Thanks
Anik

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Hi Anik,

As far as I know there is no existing AMP file that makes available the feature of putting variables to the template.

I guess the best you could do if you don't wanna upgrade it to 4 is either modify the MailActionExecuter providing that feature (you can download the SDK for version 4 and check how they do it there), or create your own action making it available

Regards,
Adei