Render data variables from Email Template Using Script

Jira code: TRS-109

We can send emails to the end-user using an email template irrespective of any record, field data variables defined in the email template.
We can define custom data variables inside the email template, and replace these variables using Regurel expressions and finally process these emails using scripts. Using this we can apply search results and other custom data to the email template.
N/render module used to render the email template data to JS variable.

alterEmailContent: function(dataObj) { //Alter the email content and subject by replacing the custom variable from the email template

                var emailDataObject = {};
                var mapObj = {
                    //JJ_ENTITY_RECEIVER: mailObj.Recepient.name,
                    CUST_VAR_1: dataObj.DATA1,
 var emailContent = (render.mergeEmail({ templateId: EMAIL_TEMPLATE_ID }).body).toString(); //email content


                        var emailSubject = (render.mergeEmail({ templateId: EMAIL_TEMPLATE_ID }).subject).toString(); //email subject                   

 CUST_VAR_2: '<b>' + dataObj.DATA2 + '</b>',
                    CUST_VAR_3: '<b>' + format.format({ value: Number(dataObj.DATA3).toFixed(2), type: format.Type.CURRENCY }) + '</b>',
                    CUST_VAR_4: '<b>' + 'The ' + formatFundName(dataObj.DATA4) + ' Fund' + '</b>',
                };
                var mapSubObj = {
                    CUST_VAR_5: dataObj.DATA5
                };
                var re = new RegExp(Object.keys(mapObj).join("|"), "gi");
                emailDataObject.body = emailContent.replace(re, function(matched) {
                    return mapObj[matched];
                });
                var re = new RegExp(Object.keys(mapSubObj).join("|"), "gi");
                emailDataObject.subject = emailSubject.replace(re, function(matched) {
                    return mapSubObj[matched];
                });
                return emailDataObject
            },

Leave a comment

Your email address will not be published. Required fields are marked *