How to add email script to email template

joshehren
Kilo Expert

Hello.   Thanks in advance for your help.   I've seen a number of discussions on how to do add an email script to an email template, but it isn't working for me.

Scenario:   I have a notification where I add header and footer templates by using a ${mail_script:header} and a ${mail_script:footer} email script.  

In the footer template, I would like to include an email script that updates the year automatically.   However, when the footer template is added into the notification, the email script (mail_script:GetYear) doesn't convert to the year.   However, it works fine if I keep it in the notification, which is not what I want...email.png

Any advice?

Thanks again,

josh

1 ACCEPTED SOLUTION

Hi Josh,


Sorry!!! I don't know why this is not working .May be what Berny mentioned above that can be the reason . If not then you can achieve this by writing a script include and calling   it from mail script.


Script Include:


Name: EmailUtils


Client Callable:Unmarked


Active:Marked


Script:


var EmailUtils = Class.create();


EmailUtils.prototype = {


  initialize: function() {


  },


  emailFooter: function(){


    var time=gs.now();


  var SplitTime=time.split('-');


  var Year=SplitTime[0];


  var Emailfooter='<table id="body" style="width: 100%; height: 100%; border-collapse: collapse; background-color: #f5f5f5;" border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#f5f5f5"><tbody><tr><td align="center" valign="top" bgcolor="#f5f5f5" width="100%" height="100%"> </td></tr><tr><td style="width: 550px; height: 20px;" width="550" height="20"> </td></tr><tr><td style="width: 550px; font-size: 11px; font-family: Arial, Helvetica, sans-serif; color: #333; text-align: center; line-height: 19px;" align="center" width="550">Liberty University Information Technology<br /> 1971 University Boulevard &bull; Lynchburg, VA 24515 &bull; (866) 447-2869<br /> &copy; Copyright '+Year+' &bull; Liberty University is a Registered Trademark &bull; <a href="http://www.liberty.edu/index.cfm?PID=6901">Privacy Policy</a></td></tr><tr><td style="width: 550px; height: 30px;" width="550" height="30"> </td></tr></tbody></table>';


  return Emailfooter;


  },


  type: 'EmailUtils'


};


find_real_file.png


Email Notification Script:


Name:email_footer


Script:


(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,


/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,


/* Optional GlideRecord */ event) {


  var emailUtils = new EmailUtils();


  template.print("<tr><td>"+ emailUtils.emailFooter()   +"</td></tr>");


})(current, template, email, email_action, event);


find_real_file.png


Notification:


Message HTML:${mail_script:email_footer}


find_real_file.png



Notification Preview:




find_real_file.png



Let me know for further queries ............



Thanks,


Farukh



Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

10 REPLIES 10

Hi Josh,



Could you please confirm me that is 'footer'   template or mail script ? ,as you are calling it by using ${mail_script:footer} so it looks like a another one mail script which containing 'GetYear' mail script.



Thanks,


Farukh


Faruk,


The ${mail_script:footer} grabs the html from the footer template (a trick I learned from this discussion:Re: Apply Email Template in Notification😞



find_real_file.png



In this case, the template is one whose html is provided in my 9/23 9:30am reply.



Thanks,


josh


Hi Josh, try Footer with the F in upper case since that's how your mail script is named.



Thanks,


Berny


In other words, use the following:



${mail_script:Footer}



instead of...



${mail_script:footer}



I hope this helps!



Thanks,


Berny


Hi Josh,


Sorry!!! I don't know why this is not working .May be what Berny mentioned above that can be the reason . If not then you can achieve this by writing a script include and calling   it from mail script.


Script Include:


Name: EmailUtils


Client Callable:Unmarked


Active:Marked


Script:


var EmailUtils = Class.create();


EmailUtils.prototype = {


  initialize: function() {


  },


  emailFooter: function(){


    var time=gs.now();


  var SplitTime=time.split('-');


  var Year=SplitTime[0];


  var Emailfooter='<table id="body" style="width: 100%; height: 100%; border-collapse: collapse; background-color: #f5f5f5;" border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#f5f5f5"><tbody><tr><td align="center" valign="top" bgcolor="#f5f5f5" width="100%" height="100%"> </td></tr><tr><td style="width: 550px; height: 20px;" width="550" height="20"> </td></tr><tr><td style="width: 550px; font-size: 11px; font-family: Arial, Helvetica, sans-serif; color: #333; text-align: center; line-height: 19px;" align="center" width="550">Liberty University Information Technology<br /> 1971 University Boulevard &bull; Lynchburg, VA 24515 &bull; (866) 447-2869<br /> &copy; Copyright '+Year+' &bull; Liberty University is a Registered Trademark &bull; <a href="http://www.liberty.edu/index.cfm?PID=6901">Privacy Policy</a></td></tr><tr><td style="width: 550px; height: 30px;" width="550" height="30"> </td></tr></tbody></table>';


  return Emailfooter;


  },


  type: 'EmailUtils'


};


find_real_file.png


Email Notification Script:


Name:email_footer


Script:


(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,


/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,


/* Optional GlideRecord */ event) {


  var emailUtils = new EmailUtils();


  template.print("<tr><td>"+ emailUtils.emailFooter()   +"</td></tr>");


})(current, template, email, email_action, event);


find_real_file.png


Notification:


Message HTML:${mail_script:email_footer}


find_real_file.png



Notification Preview:




find_real_file.png



Let me know for further queries ............



Thanks,


Farukh



Hit like, Helpful or Correct depending on the impact of the response