Don’t Miss it: Top Strategies for Driving Diversity

days / hours / minutes / seconds

Register Here »
NetSuite logo
NETSUITE RESOURCES
workplace by meta logo
FUTURE
OF WORK WORKPLACE BY META
University icon
CUSTOMER EDUCATION blog
Atlassian Logo
Adoption blog
How-to
October 19, 2023
|
1.5 min
reading time

SuiteScript 2.0: Sample Code For Sending an Email Using a Scriptable Template

Share this article
/*SoMe buttons*/ <-- Facebook Share Button Code --> <-- Facebook Share Button Code --> <-- Twitter Share Button Code --> <-- Twitter Share Button Code --> <-- Linkedin Share Button Code --> <-- Linkedin Share Button Code -->

NetSuite SuiteScript is a fascinating tool with a lot of capabilities and options. Ultimately, SuiteScript is useful for creating any number of things. You just need to know the code to do it.

For example, say you wanted to use SuiteScript to send an email using a scriptable template. This is completely doable! With SuiteScript 1.0, you can achieve this using the nlapiCreateEmailMerger() API. With SuiteScript 2.0, the equivalent is the render.mergeEmail method.

To help you get a handle on this, we’ve built and tested a script for you to try out yourself.

Important Notes

If you want to try building out this code in SuiteScript 2.0, there are just a few things you need to keep in mind:

  • The render.mergeEmail options like transactionId does not attach the message record to that record (the sales order record, for example). It is only used to render the record’s values based on the variables in the scriptable template.
  • To successfully attach the email to the desired record, use the relatedRecords parameter from the email.send method.
  • The templateId variable is the internal ID of the email templates, as seen on Documents > Templates > Email Templates.

You can access the sample code to send an email using a scriptable template below:



var transactionId = 4022538; 
var mergeResult = render.mergeEmail({
templateId: 25,
entity: null,
recipient: null,
supportCaseId: null, 
transactionId: transactionId,
customRecord: null
});
var emailSubject = mergeResult.subject; 
var emailBody = mergeResult.body; 
email.send({
author : author, 
recipients : emailRecipients, 
subject : 'test', 
body : emailBody, 
relatedRecords : {
transactionId : transactionId
}
});

Get Even More Out of Your NetSuite

With ServiceRocket, you’ll get certainty, expertise and success built into your NetSuite implementation, configuration and custom development. When you work with us, you get access to NetSuite-trained Certified Developers with over 400+ NetSuite scripts and 50+ Suitelet workflows combined. Rest assured that ServiceRocket will help you find success and provide you with the opportunities you need to transform your business.

Do you have NetSuite license management, implementation, administration, support or custom development needs? We’ve got your back! Contact our NetSuite Certified Experts today.

Ensure the highest return on your NetSuite investment with our custom development or administrative services.

Learn MoreServiceRocket Backed - We've got your back badge