ANS-1322 · SUITESCRIPT DEVELOPMENT
How NetSuite’s Approve Button Triggers Scripts and Handles Record Changes
Understand how user event scripts are triggered by the Approve button on transactions, and the implications for saving record changes and preventing approval.
Short answer
The NetSuite Approve button triggers user event scripts. While changes to the current record in beforeSubmit may persist automatically, explicit saving via record.save() or record.submitFields() is often needed in afterSubmit or for external records. To halt approval, an error must be thrown, which reverts all record changes.
Scenario
A NetSuite administrator or developer needs to implement custom logic that executes when a transaction's 'Approve' button is clicked. They need to understand how scripts are triggered, how record changes are saved, and how to conditionally prevent an approval from completing while ensuring data integrity.
Solution
The 'Approve' button on NetSuite transactions can trigger user event scripts using the 'approve' trigger. While changes made directly to the context.newRecord object within a beforeSubmit user event script persist automatically upon successful submission, explicit saving using SuiteScript 2.x functions like record.save() or record.submitFields() is generally required for changes made in afterSubmit scripts or when modifying records other than the current one in beforeSubmit.
To prevent the approval from completing and keep the transaction status as 'Pending Approval', an error must be thrown within the script. If an error is thrown, all changes made to the record during that process are reverted to their state before the button was pressed. This includes any modifications made using SuiteScript 2.x functions such as record.setValue(), record.submitFields(), or record.save().
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
