Scenario: Use dynamic value in Email Template while sending email using SuiteScript 2.0
Firstly Create an email template:

Here you can see, some variables prefixed with “NL”. You can give any name to your variable.
Now in SuiteScript 2.0 code, use below code to replace variables of email template before sending email.
//Get Transaction ID
var transactionId = recId;
//Get Email Template
var mergeResult = render.mergeEmail({
templateId: ,
entity: null,
recipient: null,
supportCaseId: null,
transactionId: transactionId,
customRecord: null
});
var emailSubject = mergeResult.subject;
var emailBody = mergeResult.body;
var issueDate = ;
var total =
var entity =
emailBody = emailBody.replace(“NLDATE”, issueDate);
emailBody = emailBody.replace(“NLTOTAL”, total);
emailBody = emailBody.replace(“NLCUSTOMERNAME”, entity);
email.send({
author : <>AUTHER ID,
recipients :,
subject : emailSubject,
body : emailBody,
attachments: [transactionFile],
relatedRecords : {
transactionId : transactionId
}
});