ANS-1387 · SUITESCRIPT DEVELOPMENT
How to Correctly Resubmit NetSuite Records After Initial Script Failure?
NetSuite scripts may encounter issues when attempting to modify and resubmit a record after an initial submission failure, often requiring a new record instance to bypass potential caching or state retention.
Short answer
When a NetSuite record submission fails via script, subsequent attempts to modify and resubmit the same record object may not work due to internal caching. The recommended approach is to create a new record instance using SuiteScript 2.x's `record.create()`, populate it with the necessary data, and then submit this fresh object with `record.save()` to ensure successful processing.
Scenario
When attempting to modify and resubmit a NetSuite record using a script after an initial submission failure, the system may retain the original error, even if the record's properties appear updated in the debugger. This behavior suggests an underlying caching mechanism or state issue preventing the modified record from being processed correctly.
Solution
When a script attempts to modify and resubmit a record after a previous submission failure, simply overriding the properties of the existing record object may not be sufficient. NetSuite's internal handling, potentially involving caching, can cause the system to retain the original error. To ensure successful resubmission, it is necessary to create a new record instance.
The recommended approach involves:
Loading the
N/recordmodule in your SuiteScript 2.x script.Creating a new record object using
record.create(). This ensures a fresh record instance, bypassing any cached states from previous failed attempts.Populating this new record object with all necessary data.
Submitting the new record using
record.save(). This operation consumes governance units, with costs varying based on the record type (e.g., custom vs. standard transaction records).Example of creating and saving a new record using SuiteScript 2.x:
javascript
// Ensure the 'record' module is loaded, e.g., define(['N/record'], function(record) { ... });
// Create a new record instance
var newSurvey = record.create({
type: SURVEY_TYPE
});
// Populate newSurvey with necessary field values from the original failed record or new data
// For example: newSurvey.setValue({ fieldId: 'name', value: 'New Survey Name' });
// Submit the new record
var newSurveyId = newSurvey.save();It is also considered best practice to verify the existence and active status of related records (such as contacts or customers) before attempting to submit the primary record, which can prevent common submission failures.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
