ANS-0699 · SUITESCRIPT DEVELOPMENT
How to Reliably Get the Correct Record ID in NetSuite afterSubmit Scripts
Understand the critical difference between nlapiGetRecordId() and record.getId() to ensure accurate data retrieval in NetSuite SuiteScript.
Short answer
When working with NetSuite afterSubmit user event scripts, nlapiGetRecordId() may not always return the correct internal ID for the record. To ensure accuracy, retrieve the new record object using nlapiGetNewRecord() and then call getId() on that object. This method guarantees the correct internal ID is obtained for the submitted record.
Scenario
Developers may encounter discrepancies when attempting to retrieve a record's internal ID within an afterSubmit user event script. Specifically, using nlapiGetRecordId() in this context can sometimes yield an incorrect or unexpected internal ID. This behavior can lead to data integrity issues or incorrect processing if subsequent operations rely on the accurate record identifier.
Solution
To ensure the correct internal ID is consistently retrieved in an afterSubmit user event script, developers should avoid using nlapiGetRecordId(). Instead, the recommended approach involves first obtaining the new record object and then extracting its ID. NetSuite Support indicates that nlapiGetRecordId() in afterSubmit() will not always return the correct internal ID for the record. The following code snippet demonstrates the correct method:
javascript
var newRecord = nlapiGetNewRecord();
var recordID = newRecord.getId();This method guarantees that the recordID variable will hold the accurate internal ID of the record that was just submitted.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
