Email Template configuration

r_daosseili
Kilo Contributor

Hello,

I was wondering if there is any possibility to configure an email template to contains only a specific header and footer, and get the body from the email notification form ?

So my email template will have a fixed header and footer and variable body which is the email notification content.

Thanks,

1 ACCEPTED SOLUTION

So templates aren't as nuanced as you're hoping.   A template will build the whole body, and doesn't distinguish between body headers, main body, and footers.


Also, it sounds like you want each notification to retain its currently defined body, which is like saying "I want to always use just a part of a template".



Only thing I can think of is to use Kalai's approach, but it requires always remembering to put the mail scripts in your notification body.   It'll look like this...



find_real_file.png


View solution in original post

10 REPLIES 10

drjohnchun
Tera Guru

To get "variable body which is the email notification content" in your email template, use email_action, which is GlideRecord object for the email notification (sysevent_email_action). So your template would look like



Email Template Message Field:


Header contents



<mail_script>


template.print(email_action.message_text);   // for Message content from Email Notification


template.print(email_action.message_html);   // for Messaage HTML content from Email Notification


</mail_script>



Footer contents



and specify this template in your email notification.



EDIT: as Reda pointed out below, this won't work because any contents in "Message HTML" or "Message text" will override the template. Please see the reply below for more details.



Please feel free to connect, follow, mark helpful / answer, like, endorse.


John Chun, PhD PMP see John's LinkedIn profile

visit snowaid


ServiceNow Advocate

It doesn't seem to work because the email notification message will override the message from the template form.


Pardon me! My rusty memory overlooked the fact that any contents in "Message HTML" or "Message text" will override the template. One kludge, if you're not using SMS, is to put the email body (HTML is OK) in the "SMS alternate" field, which surprisingly has a max length of 4,000, in Email Notification (not in template). Then your Email Template would look like



Email Template Message Field:


YOUR HEADER



<mail_script>  
template.print(email_action.sms_alternate);
</mail_script>



YOUR FOOTER



Alternatively, you could add a custom field in Email Notification to hold the email body. Do I like this solution? No, it's a hack at best, but may do the job if you want to separate the header/footer from the body. Or you could go with the solution suggested by Robert.


Thank you John Chun, I really like your solution but I think I will go with Robert and Kalaiarasan solutions.


Still shocked at how much I don't know after all these years.