ANS-0742 · SUITESCRIPT DEVELOPMENT

How to Send Email Notifications for Script Errors in NetSuite SuiteScript 2.x?

Learn how to configure SuiteScript 2.x errors to trigger email notifications for critical script failures.

Short answer

To ensure email notifications are sent for script errors in SuiteScript 2.x, use `error.create` from the `N/error` module. Set the `notifyOff` parameter within the error options object to `false` when throwing the error to prevent notification suppression.

Scenario

NetSuite users often need to be alerted immediately when a script encounters a critical error. Standard script logs of type 'ERROR' do not inherently trigger email notifications. The challenge is to implement a mechanism that ensures relevant stakeholders receive email alerts for script failures.

Solution

To ensure an email notification is sent when a script encounters an error, the script must explicitly throw an error using the error.create function from the N/error module in SuiteScript 2.x. This function requires the N/error module to be loaded. It is essential to set the notifyOff parameter within the error's options object to false. This configuration ensures that the error message triggers an email notification and is not suppressed.Example:

javascriptthrow error.create({name: 'MYCODE', message: 'My script just failed', notifyOff: false});

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant