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

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
The locale property of the user doesn't mean it matches with the browser. You can change the language of your browser.

The "Accept Language" header sets the Locale for the current user, at least it's that way how it works for webscripts

lukasz_turakiew
Champ in-the-making
Champ in-the-making
The locale property of the user doesn't mean it matches with the browser. You can change the language of your browser.
Of course this property doesn't have to match to the locale within the user`s browser.
However if we suppose that te locale must be passed at the creation stage of the workflow the user can also change the language in the browser to diffrent from which was set.
Why it would be needed(passing the locale at the creation stage of the workflow)? Let`s suppose the following scenario:

1. The workflow is created and 5 users are added to that workflow. For each user a task is created and at the create event of the task the email
to the assigne user must be sent. Passing locale as a workflow parameter doesn`t ensure that the locale passed to the workflow match to the locale in the user browser.
The code that sends emails doesn`t have to be executed in behalf of the user to which the email must be sent.

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Sure. You are right

anik
Champ in-the-making
Champ in-the-making
hi
Please Go to the reply
by lukasz_turakiewicz » 17 Dec 2011, 22:38

Hi,
I tried the code mentioned by lukasz_turakiewicz

Sample code

I tried accessing process variable from JS in FTL(email template) without any controller file.
             
               var templateArgs = new Array();
               templateArgs['workflowTitle'] = "workflowTitle";
               templateArgs['workflowPooled'] = true;
               templateArgs['workflowDescription'] = "workflowDesc";
               templateArgs['workflowId'] = "workflowId";

               var templateModel = new Array();
               templateModel['args'] = templateArgs;
               mail.parameters.template_model = templateModel;
                             
               mail.execute(search.findNode("workspace://SpacesStore/6b936fof-0758-431b-b5b4-dacb7a8d2128"))

My Question is :
Which File Node reference you are mentioning in Search Api???
Please help Smiley Sad

Thanks in advance
Anik

lukasz_turakiew
Champ in-the-making
Champ in-the-making
Hi Anik,

The node reference passed to the mail.execute method it is a node reference on which you want to execute the action. How it will be used depends on the action code. The code of the mail action is contained in org.alfresco.repo.action.executer.MailActionExecuter class - if you take a look at it you will notice "the mail action might not relate to a specific nodeRef". In my example I passed some valid nodeRef from the Alfresco repository - it may be null or if you pass the nodeRef it must exists.

Regards,
Lukasz Turakiewicz

anik
Champ in-the-making
Champ in-the-making
Hi lukasz,

Thanks for your quick response  Smiley Very Happy
But the things is I am still not very clear of node reference.

Is it the node reference of "Node in Process definition" or of some other file.
If that is the case how can i know the node reference.

Please help

Thanks
Anik

anik
Champ in-the-making
Champ in-the-making
Hi lukasz,

Thanks for your previous help.
My Code
var templateArgs = new Array();
templateArgs['workflowTitle'] = "workflowTitle";
templateArgs['workflowPooled'] = true;
templateArgs['workflowDescription'] = "workflowDesc";
templateArgs['workflowId'] = "workflowId";

var templateModel = new Array();
templateModel['args'] = templateArgs;
mail.parameters.template_model = templateModel;

mail.execute(bpm_package);
instead of node reference in mail.execute method.

Problem lies when FTL(Template file )access these variable

I am getting an exception saying
Template Exception "args" is not defined 
Please help

Thanks
Anik

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Which alfresco version are you working on?

anik
Champ in-the-making
Champ in-the-making
I am working on Enterprise 3.4.7

The thing is that email script send email if i dont access process variable.
But as soon as i try to use "args" with same script, i get a Template Exception saying
'args' not defined.

My Ftl Template is in repository(CompanyHome>DataDictionery>EmailTemplate>..<here>)
Note: I am not using any Controller File.

Is there any way to to send variable from process definition (JS) into EMail Template (FTL)?

Please Help Smiley Sad

Thanks
Anik

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
The template_model functionality is available for version 4…. so args nor any other thing you put in mail.parameters.template_model won't be available…

You can check the code in the SDK for MailActionExecuter class. Compare it with the one for version 4 and you'll see that version 4 has the template_model parameter.

Regards,
Adei