ANS-1120 · PRINTING, PDF & EMAIL TEMPLATES

How to Programmatically Email a Sales Order in NetSuite SuiteScript 2.x

Learn to generate and send sales order email content dynamically using NetSuite's SuiteScript 2.x N/render and N/email modules.

Short answer

To programmatically email a sales order in NetSuite, leverage SuiteScript 2.x's N/render module to generate the transaction's HTML content. Then, use the N/email module's email.send() function to dispatch the email with the generated content to the desired recipients, replicating the standard customer sales order email.

Scenario

A NetSuite user requires the ability to programmatically generate and send the standard sales order confirmation email. This is necessary when the default "To Be E-mailed" checkbox functionality is insufficient for specific business process automation, such as custom workflows or scheduled scripts.

Solution

To programmatically generate and send a sales order email using SuiteScript 2.x, the N/render and N/email modules are utilized. This approach replicates the standard email content a customer receives when the "To Be E-mailed" checkbox is selected on a sales order.nn

  1. Generate the HTML content of the sales order using render.transaction().n

  2. Send the generated content as an email using email.send().

    The following SuiteScript 2.x example demonstrates this process:nn

javascriptn// Assume 'salesOrderId', 'author', 'recipient', 'subject', and 'cc' variables are already defined.n// Ensure 'N/render' and 'N/email' modules are loaded in your SuiteScript 2.x context.nnvar salesOrderContent = render.transaction({n    entityId: salesOrderId,n    printMode: render.PrintMode.HTMLn});nnemail.send({n    author: author,n    recipients: recipient,n    subject: subject,n    body: salesOrderContent,n    cc: ccn});n

Expert NetSuite Support

Need help with this NetSuite issue?

Printing, PDF & Email Templates consulting and configuration support

Talk to a consultant