The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Apply Email Template in Notification

Steven Young
Tera Guru

Hey Again all you Genius's.   I need your help again.

This is kind of a "idea" rather than it being functional (i think).

So here's the deal.

I love ${mail_script:scriptname}   it's awesome.   Very functional, works like a charm.

We have a request item that we have an approval email for.   Then there is a UI action that was create to fire an Event.   We created a 2nd email notification to accept this event to fire the "Resend email"

here's the deal.

The approval email we have a ${mailscript}   at the very top which contains our approval/reject links.   and Information about the request.
Then we have the BODY of the email.   Contains the variables of the request.

Then we have 2 ${mailscript}'s at the bottom with some "for the administrator"   which tells us the ticket number, what email notification send this email, and so forth.

approval.JPG

Here is where the question comes in.   We cant use an HTML template for all the notifications because we add different ${mailscripts}
approval2.JPG

What i'm wanting to know is:
Can we Create a template, that is dynamic like the mail scripts

So in my email notification, i dont have a template "attached" and used.
BUT.   i used something like ${template:templatename}   Because the body of my email wont change.

Is there a way to do something like so.

${mail_script:Approval-Reminder}
${mail_script:Approval-Links}


${template:templatename}

${mail_script:Approval-Additional}


${mail_script:Approval-Administrator}

Where the ${template} will actually pull the HTML data out of the template.
This way i would only have to update it 1 time and it would update in all 3 of my notifications.
I do not want to use the text box.   i want to use HTML.   i dont want to have to use the <mail_script> template.print() for every single line,   Hence using the HTML (WYSIWYG)

Does that make any sense at all?

it would be great for the templates if you attach it as is to the email and it's used with no modifications.   or if you could "call" the template data into the actual email notification like the mailscripts.

1 ACCEPTED SOLUTION

Steven Young
Tera Guru

So i found my answer.   Dot Walk.


Create an email script, say called "template"


Script will be


template.print(email_action.template.message_html);



That will take the reference field of the "template" from the email notification and then pull the HTML field from the template.



Then in the email notification you can do a ${mail_script:template}   and that is all that is needed.



So now my email Notification html box looks like so:
Capture1.JPG




It will translate into this


Capture2.JPG


View solution in original post

34 REPLIES 34

are you using the standard   mailto:mailto.approve       and mailto.rejection     scripts for your approval and rejection links?


and i'm guessing you are using microsoft outlook as your main email client?


Yeah, that's correct. The OOTB mailto templates.



On 29 Nov 2016 12:11 AM, "christianlife21" <


Ok,   so a very complicated problem because of the HTML support in Outlook.



I do all of my testing in a Development site, and it emails to my google account.


The issues come in that the Code works just fine.   but Outlook doesn't render the same.



This is google, or any other browser for that matter:
find_real_file.png




Here is outlook.


find_real_file.png




That is with the simplified code.



A little more complex coding and Outlook displays it like so:


find_real_file.png




All of which the links work





OK,   So After a little more testing, i was able to get it "Mostly" working in Outlook.



Here is what it looks like in Gmail.
find_real_file.png




And this is what it will look like in Outlook 2013.



find_real_file.png




Very similar, but no rounded edges,   and there is less that you can do in the background.



This OK with you?   or do you need something else?


This looks amazing, Steve.



The rounded edges one looks pretty cool, but if that wouldn't work in Office 365 then the rectangular one works for me.



Thanks again !!


ok.   This is all being done by email script.



so Create you a new Email Script.


Title:   ApprovalLinks


the mailscript would be   ${mail_script:ApprovalLinks}




In your email notifications you would replace your ${mailto:}   scripts with this one.     ${mail_script:ApprovalLinks}



You need to edit line 11 with the email that you guys send email to


you need to edit lines 19, 20, 21 with the verbiage that you want the button to say.   the "type" puts the number in the button



those are the main things you need to edit.     If you dont want the view button   comment out the entire first section.



otherwise there are notes all over the script for you.


Script is:



(function runMailScript(current, template, email, email_action, event) {



  //KEEP IN MIND THAT THE ROUNDED EDGED AND OTHER OPTIONS MAY NOT WORK CORRECTLY IN MICROSOFT OUTLOOK.


  //KEEP IN MIND THAT THE ROUNDED EDGED AND OTHER OPTIONS MAY NOT WORK CORRECTLY IN MICROSOFT OUTLOOK.




  //------------------------------------------------------------------------------------------------------------------------


  //SET EMAIL THAT WILL BE SENT BACK TO YOUR SERVICE-NOW INSTANCE.   WHETHER A COMPANY DISTRUBUTION LIST THAT FWD'S TO


  //SERVICE-NOW OR AN EMAIL THAT IS SENT DIRECTLY TO SERVICE-NOW.   ENTER THE EMAIL BETWEEN THE SINGLE ' ' QUOTES BELOW.


  //------------------------------------------------------------------------------------------------------------------------


  var setEmail = 'test@test.org';                                               //<<<<------------   SET YOUR EMAIL



  var type = "${sysapproval}"; //the number that shows in the button   ex.   current.number   "${sysapproval}"


  // var type = current.number;




  //set the wording of the View, Approval, and Reject Buttons


  //DO NOT REMOVE THE TYPE FROM THE LINES.


  var viewButton = "VIEW   >>>   " + type;


  var approvalButton = "APPROVE .... " + type;


  var rejectButton = "REJECT +++ " + type;










  //SECTION 1 = VIEW TASK BUTTON


  //**************************************************************************************************************************************************


  //This section is for the "VIEW $tasknumber$ button         if you do not want the View Item button, comment out this section.


  //**************************************************************************************************************************************************



  //------------------------------------------------------------------------------------------------------------------------


  //the View RITM number for approvals.


  //------------------------------------------------------------------------------------------------------------------------




  //If you want this button centered, use the next line and the template.print("</div>"); line at the end of this section.


  //template.print('<div style="text-align: center;">');




  //build the link for the RITM number   will take you directly to view the RITM of which they are being asked to approve


  //additional scripting required to approve changes, or other tables


  //using just the current.getLink()   takes you to the approval itself.


  // var viewlink = 'sc_req_item.do?sys_id=' + current.document_id;               //current.getLink();


  var viewlink = '';


  var task = new GlideRecord('task');


  task.addQuery('sys_id', current.document_id);


  task.query();


  if (task.next()) {


  viewlink = task.getLink();


  }


  // viewlink = current.sysapproval.getLink();                                     //used for testing purposes




  var viewfontSize = 'font-size: 16px;';                                                   //size of the text in the buttons


  var viewfontFamily = 'font-family: Helvetica, Arial, sans-serif;';


  var viewtextDecoration = 'text-decoration: none;';                           //text decorations could be none|underline|overline|line-through|initial|inherit;


  var viewcorners = 'border-radius: 5px;';                                               //the higher this number the rounder the corners will be


  var viewpadding = 'padding: 0px;';                                                           //how much space around the outside of the letter in between the letters and the border


  var viewborder = 'border: 10px solid blue;';                                       //how thick do you want the border and what color?


  var viewBGColor = 'background-color: blue;';                                       //set the background (button) color for approval button


  var viewTxTcolor = 'color: white;';                                                         //set the text color within the button.



  template.print('<font face="helvetica">');


  template.print('<a href="' + viewlink + '"');


  template.print('style="' + viewBGColor + viewborder + viewTxTcolor + viewcorners + viewfontSize + viewfontFamily + viewpadding + viewtextDecoration);


  template.print('">');


  template.print(viewButton);                                                                         //Wording that is visible in the button.


  template.print('</a>');


  template.print('</font>');


  //template.print('<br>');


  //template.print('<br>');


  //template.print('</div>');



  //**************************************************************************************************************************************************


  //END OF SECTION for the "VIEW $tasknumber$" button     END OF SECTION     END OF SECTION     END OF SECTION


  //**************************************************************************************************************************************************











  //SECTION 2 = APPROVAL BUTTON AND REJECT BUTTION


  //**************************************************************************************************************************************************


  //THIS IS THE SECTION FOR THE APPROVAL AND REJECTION "BUTTONS"


  //**************************************************************************************************************************************************




  // options for BOTH approval and Reject Buttons


  var align = 'text-align: center';


  var fontSize = 'font-size: 16px;';                                                         //size of the text in the buttons   OVERALL SIZE OF THE BUTTON


  var fontFamily = 'font-family: Helvetica, Arial, sans-serif;';


  var textDecoration = 'text-decoration: none;';                                 //text decorations could be none|underline|overline|line-through|initial|inherit;


  var corners = 'border-radius: 5px;';                                                     //the higher this number the rounder the corners will be   (DOES NOT WORK IN MICROSOFT OUTLOOK)


  var webKitBorder = '-webkit-border-radius: 3px;';


  var mozBorder = '-moz-border-radius: 3px;';


  var display = 'display: inline-block;';





  //http://www.rapidtables.com/web/html/mailto.htm       is a good example of how to build the links


  //BULID THE LINK FOR THE APPROVAL MAILTO:


  var applink = '<a href="mailto:' + setEmail + '?subject=Re:%20' + type + '%20-%20approve&body=---------------DO%20NOT%20EDIT%20OR%20DELETE%20ANYTHING%20BELOW%20HERE---------------' + type + ''   + email.watermark   + '"';



  //BULID THE LINK FOR THE REJECTION MAILTO:


  var rejlink = '<a href="mailto:' + setEmail + '?subject=Re:%20' + type + '%20-%20reject&body=Rejection Notes:%20---------------DO%20NOT%20EDIT%20OR%20DELETE%20ANYTHING%20BELOW%20HERE---------------' + type + '' + email.watermark   + '"';




  //if you want the buttons centered,   use this line and the template.print("</div>"); line at the end of this section ,   otherwise they should be commented out.


  template.print('<div style="text-align: center;">');






  //------------------------------------------------------------------------------------------------------------------------


  //APPROVAL LINK AND BUTTON OPTIONS   *******   APPROVAL LINK AND BUTTON OPTIONS   *******   APPROVAL LINK AND BUTTON OPTIONS


  //------------------------------------------------------------------------------------------------------------------------



  template.print('<font face="helvetica">');


  var appBGColor = 'background-color: green;';                                               //set the background (button) color for approval button


  var appTxTcolor = 'color: white;';                                                                   //set the text color of the approval button


  var apppadding = 'padding: 0px;';                                                                     //how much space around the outside of the letter in between the letters and the border needs to be 0 for Outlook


  var appborder = 'border: 10px solid green;';                                               //set the text color within the button.   //should be greater than 10 to look right in Outlook



  template.print(applink);


  template.print('style="' + appBGColor + appborder + appTxTcolor + fontSize + fontFamily + textDecoration + corners + webKitBorder + mozBorder + display + apppadding);


  template.print('">');


  template.print(approvalButton);                                                                       //Wording that is visible in the button.


  template.print('</a>');


  template.print('</font>');







  //------------------------------------------------------------------------------------------------------------------------


  //HOW MANY SPACES BETWEEN THE APPROVAL BUTTON AND THE REJECT BUTTON?   NONE FOR BUTTONS RIGHT NEXT TO EACH OTHER


  //------------------------------------------------------------------------------------------------------------------------


  template.print('<br>');


  template.print('<br>');


  // template.print('<br>');


  // template.print('<br>');







  //------------------------------------------------------------------------------------------------------------------------


  //REJECT LINK AND BUTTON OPTIONS   *******   REJECT LINK AND BUTTON OPTIONS   *******   REJECT LINK AND BUTTON OPTIONS


  //------------------------------------------------------------------------------------------------------------------------



  template.print('<font face="helvetica">');


  var rejBGColor = 'background-color: red;';                                               //set the background (button) color for rejection button


  var rejTxTcolor = 'color: white;';                                                               //set the text color within the button.


  var rejpadding = 'padding: 0px;';                                                                 //how much space around the outside of the letter in between the letters and the border needs to be 0 for Outlook


  var rejborder = 'border: 10px solid red;';                                               //set the text color within the button.   //should be greater than 10 to look right in Outlook



  template.print(rejlink);


  template.print('style="' + rejBGColor + rejborder + rejTxTcolor + fontSize + fontFamily + textDecoration + corners + webKitBorder + mozBorder + display + rejpadding);


  template.print('">');


  template.print(rejectButton);                                                                         //Wording that is visible in the button.   the "type"   is called above being the RITM number


  template.print('</a>');


  template.print('</font>');




  //End of the Center code.   Only use this if the line 29 is being used


  template.print('</div>');





  //------------------------------------------------------------------------------------------------------------------------


  //ANY ADDITIONAL SPACES YOU MAY NEED AFTER THE REJECT BUTTON.   You can also use line breaks from another script if necessary


  //------------------------------------------------------------------------------------------------------------------------


  // template.print('<br>');


  // template.print('<br>');


  // template.print('<br>');


  // template.print('<br>');



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