Generating professional PDFs, sending templated emails, and producing formatted statements are everyday needs in NetSuite customizations. The N/render module is your gateway to all of this β it lets SuiteScript programmatically render Advanced PDF/HTML Templates, BFO-based print templates, and email templates into real output files and messages that you can save, attach, email, or return to the browser.
In this guide you will learn what the N/render module is, how to render a transaction PDF, how to send a template-based email, a practical real-world scenario, when to reach for N/render, and the best practices that keep your rendered output reliable.
What Is the N/render Module?
The N/render module provides methods to turn NetSuite records and data into formatted output. Its three most-used methods are renderRecordToPDF(), which takes a transaction record and an Advanced PDF/HTML Template and returns a PDF file object; mergeEmail(), which merges record data into an email template and returns a rendered email body and subject; and create(), which builds a custom renderer you can hydrate with any XML data and a template.
The rendered output is always a NetSuite file object or an email-merge result, making it easy to pipe straight into N/file to save to the cabinet, or into N/email to send to a recipient.
Rendering a Transaction to PDF
The most common use of N/render is converting a sales order, invoice, or purchase order into a PDF. You pass the record’s internal ID and the template ID to renderRecordToPDF(), and NetSuite returns a fully rendered PDF file object ready to email or save.
Code Examples
Example 1 renders an invoice to a PDF using an Advanced PDF/HTML Template and emails it to the customer.
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/render', 'N/email', 'N/record'], (render, email, record) => {
const afterSubmit = (context) => {
if (context.type !== context.UserEventType.CREATE) return;
const invoiceId = context.newRecord.id;
// Render the invoice to PDF using an Advanced PDF/HTML Template
const pdfFile = render.renderRecordToPDF({
entityid: invoiceId,
printMode: render.PrintMode.PDF,
internalid: invoiceId,
template: { id: 123 } // your template internal ID
});
// Load the invoice to get the customer email
const inv = record.load({ type: record.Type.INVOICE, id: invoiceId });
const custId = inv.getValue('entity');
// Email the rendered PDF as an attachment
email.send({
author: -5, // NetSuite system author
recipients: custId,
subject: 'Your Invoice #' + inv.getValue('tranid'),
body: 'Please find your invoice attached.',
attachments: [pdfFile]
});
};
return { afterSubmit };
});
Example 2 uses mergeEmail() to merge a customer record into a NetSuite email template and sends the resulting personalised message.
define(['N/render', 'N/email'], (render, email) => {
const execute = () => {
const customerId = 1234; // internal ID of the customer
const templateId = 56; // internal ID of the email template
// Merge the email template with customer record data
const mergeResult = render.mergeEmail({
templateId: templateId,
entity: {
type: 'customer',
id: customerId
},
recipient: {
type: 'customer',
id: customerId
}
});
// Send the merged email
email.send({
author: -5,
recipients: customerId,
subject: mergeResult.subject,
body: mergeResult.body
});
log.audit('Email sent', 'Merged email sent to customer ' + customerId);
};
return { execute };
});
Example 3 uses render.create() to build a custom PDF from an Advanced PDF/HTML Template and a record loaded in script, then saves it to the File Cabinet.
/**
* @NApiVersion 2.1
* @NScriptType ScheduledScript
*/
define(['N/render', 'N/record', 'N/file'], (render, record, file) => {
const execute = () => {
const soId = 5678; // sales order internal ID
// Load the sales order record
const so = record.load({
type: record.Type.SALES_ORDER,
id: soId
});
// Create a renderer and bind the record
const renderer = render.create();
renderer.templateId = 99; // Advanced PDF/HTML Template ID
renderer.addRecord({ templateName: 'record', record: so });
// Render to PDF file object
const pdfFile = renderer.renderAsPdf();
pdfFile.name = 'SalesOrder_' + so.getValue('tranid') + '.pdf';
pdfFile.folder = -15; // SuiteScripts folder
const fileId = pdfFile.save();
log.audit('PDF saved', 'File Cabinet ID: ' + fileId);
};
return { execute };
});
A Real-World Use Case
Consider a company that needs to send a personalised invoice PDF to each customer the moment an invoice is approved. A User Event script on the afterSubmit of the Invoice record calls renderRecordToPDF() to produce the PDF, then immediately calls email.send() with the PDF as an attachment. The customer receives a beautifully formatted invoice within seconds of approval, with zero manual steps from the finance team.
When to Use the N/render Module
Use N/render whenever you need to produce a formatted document or a template-driven email from a script. It is the right choice for auto-sending invoice PDFs on approval, generating statements and reports as PDFs for archiving, sending bulk personalised emails using NetSuite email templates, and producing PDF packing slips on fulfillment. Avoid using it for plain HTML output in Suitelets (use serverWidget instead) or for situations where a simple string-based email body is sufficient.
Best Practices
Always reference your Advanced PDF/HTML Template by internal ID rather than name, since names can change. Test your template layout in the NetSuite UI before calling it from script to catch layout issues early. When emailing PDFs, prefer NetSuite system authors (-5) over employee records to avoid failures when employees are deactivated. For bulk PDF generation, use a Map/Reduce script and render one PDF per key to stay within governance limits. Always handle errors with try-catch so a single bad record does not stop processing for the entire batch.
The N/render module is one of the most impactful tools in the SuiteScript library for customer-facing output. Whether you are auto-sending invoice PDFs, creating personalised bulk email campaigns, or archiving rendered statements to the File Cabinet, N/render makes it all possible with just a few lines of code. Build your first renderRecordToPDF() call, confirm the output looks right, and then layer in mergeEmail() and the custom renderer as your needs grow.
Discover more from The NetSuite Pro
Subscribe to get the latest posts sent to your email.
Leave a Reply