Get email template message into another email template

Sprankle
Tera Contributor

I have a requirement to get the email template eg ABC i need to add this ABC template into another email temaplate, How can we achieve.

1 REPLY 1

M Iftikhar
Kilo Sage

Hi @Sprankle

 

To embed one email template within another, you should use a mail script.

 

First, create a new mail script (found under System Notification > Email > Notification Email Scripts). Inside this script, you'll use a GlideRecord to query the Email Template [sysevent_email_template] table and find your desired template ("ABC") by its name. Once located, retrieve the content from its message_html field. Then, use template.print() to insert that HTML content directly into your email.

 

Finally, in your main email template, call the script by adding the following tag where you want the content to appear: ${mail_script:your_script_name_here}.

Here is a sample script:

(function runMailScript(current, template, email, email_action, event) {
    // Get the email template by its name
    var emailTemplate = new GlideRecord('sysevent_email_template');
    if (emailTemplate.get('name', 'ABC')) { // Replace 'ABC' with the name of your template
        
        // Print the HTML body of the template
        template.print(emailTemplate.getValue('message_html'));
    }
})(current, template, email, email_action, event);

 

Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.