Set Default Email Template
Is there a way to set the email template on a custom record?
I have created a custom record type, but when I click the email button on the form I have to manually select the email template every time. Is there a way to do this in SuiteScript 2.0?
Yes, there is a way to set the email template on a custom record in SuiteScript 2.0. You can use the following steps:
- Load the custom record using the
N/record.load()
method. - Set the
emailTemplate
property of the record to the internal ID of the email template that you want to use. - Save the record using the
N/record.submit()
method.
For example, the following code snippet shows how to set the email template for a custom record with the internal ID of 12345
:
const record = N/record.load({
type: 'customrecord_my_custom_record_type',
id: 12345
});
record.emailTemplate = 54321; // Internal ID of the email template
N/record.submit(record);
You can also use SuiteScript to set the email template for a custom record on creation or update. For example, the following code snippet shows how to set the email template for a custom record when it is created:
const record = N/record.create({
type: 'customrecord_my_custom_record_type',
defaultValues: {
emailTemplate: 54321 // Internal ID of the email template
}
});
N/record.submit(record);
Or, you can use SuiteScript to set the email template for a custom record when it is updated:
const record = N/record.load({
type: 'customrecord_my_custom_record_type',
id: 12345
});
if (!record.emailTemplate) {
record.emailTemplate = 54321; // Internal ID of the email template
}
N/record.submit(record);
By using SuiteScript to set the email template for a custom record, you can automate the process and save yourself time.
Thanks Anil for this. Would you deploy this script on pageinit or beforeload or somewhere else?
Thanks for the reply. What event should i trigger this from? After Submit?
tyn
Is this Email Message located to a subtab? If so, I don’t think you can’t set this.