We can use email templates for easily sending emails between two records having a contact. Email templates are helpful when the emails should follow a specific format or have some common content like company logo and address.
Email templates can be accessed using the navigation: Documents> Templates > Email templates
If needed to add field values from any custom record into the email template, follow these steps:
1.Open the template in ‘edit’ mode and use the text editor option.
2.Select ‘Custom record’ option from ‘Record Type’ drop down.
3.Use the ‘Field type’ and ‘Insert field’ drop downs after placing cursor in the template document where field is to be added. The ‘Field type’ drop down will populate all custom records including custom records and ‘Insert Field’ drop down will show the list of fields from the record selected.
Any field values from any record can be added in this manner. But these fields will be added to the email only if the mail is sent using the “Email” option from one of the custom records in view mode.
When used the template from a suitelet to send email, the values will not be visible by default. To make field values visible in email use the customRecord option in render.mergeEmail() function.
Refer the suitelet function code for more details(The arguments passed to the function are email id of recepient and internal id of the custom record):
const recordOperation = {
/**
* Function to send email reply
* @param emailId Email id of contact
* @param internalId Internal id of lead
*/
createEmailRecord: (emailId, internalId) => {
try {
var emailTemplate = TEMPLATE_ID;
var myMergeResult = render.mergeEmail({
templateId: emailTemplate,
entity: null,
recipient: null,
supportCaseId: null,
transactionId: null,
customRecord: {
type: 'customrecord_online_contact',
id: internalId
}//Added custom record online contact to fetch values to email template
});
var emailBody = (myMergeResult.body).toString();
var emailSubject = (myMergeResult.subject).toString();
email.send({
author: ADMIN_INTERNAL_ID,//id of admin
recipients: emailId,
subject: emailSubject,
body: emailBody,
bcc: [ADMIN_INTERNAL_ID],//id of admin,
relatedRecords: {
customRecord: {
id: internalId,
recordType: ONLINE_CONTACT_TYPE_ID//Internal id of custom record type: online contact
}}
// attachments: [fileObj]
});
log.debug("Created email and attached to online contact successfully");
}catch (err){
log.debug("Error in createEmailRecord function", err);
}
}
}