Communication is key in every business. In NetSuite, many processesālike approvals, order updates, or overdue invoicesārequire notifying the right people at the right time. While workflows (SuiteFlow) can handle simple cases, sometimes you need more flexibility. Thatās where SuiteScript comes in.
In this blog, weāll show a real-world example of using SuiteScript to send automated email notifications in NetSuite.
š ļø Why Automate Emails with SuiteScript?
- Flexibility: Add dynamic logic (e.g., send emails only if a condition is met).
- Personalization: Customize subject lines and message bodies.
- Integration: Trigger emails based on external data or APIs.
- Efficiency: Eliminate manual follow-ups and reminders.
š Use Case: Email Notification on Invoice Creation
Imagine your company wants to automatically email customers when an invoice is created, including invoice details.
Hereās how you can do it with a User Event Script.
š» SuiteScript 2.1 Example
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/record', 'N/email', 'N/runtime', 'N/log'],
(record, email, runtime, log) => {
const afterSubmit = (context) => {
try {
if (context.type !== context.UserEventType.CREATE) return;
const invoice = context.newRecord;
const customerId = invoice.getValue('entity');
const invoiceId = invoice.id;
// Get customer email
const customerEmail = record.load({
type: record.Type.CUSTOMER,
id: customerId
}).getValue('email');
if (customerEmail) {
email.send({
author: runtime.getCurrentUser().id, // sender
recipients: customerEmail,
subject: `Your Invoice #${invoiceId}`,
body: `Hello, \n\nThank you for your business. Your invoice #${invoiceId} has been created.\n\nRegards,\nFinance Team`
});
log.debug('Email Sent', `Invoice email sent to ${customerEmail}`);
}
} catch (e) {
log.error('Error Sending Invoice Email', e.message);
}
};
return { afterSubmit };
});
š What This Script Does
- Runs on the Invoice record.
- Triggers after a new invoice is created.
- Loads the customer record to fetch the email address.
- Sends an email with invoice details.
- Logs success or error messages.
ā Best Practices
- Always test email scripts in sandbox first.
- Use templates for more complex email designs.
- Add conditions (e.g., donāt email if invoice is in draft).
- Avoid sending duplicate emails by checking status.
- Log messages for troubleshooting.
š Other Real-World Email Use Cases
- Notify managers when a purchase order exceeds $10,000.
- Alert sales reps when a lead is assigned to them.
- Send reminders for overdue invoices.
- Email customers with tracking details after fulfillment.
ā Final Thoughts
SuiteScript gives you the flexibility to automate personalized, dynamic email notifications in NetSuite. Whether itās invoices, approvals, or customer updates, you can ensure the right people get the right message at the right timeāwithout manual work.
With just a few lines of code, you can turn NetSuite into a proactive communication tool for your business.
Leave a comment