ANS-1064 · SUITESCRIPT DEVELOPMENT
How Do User Event Scripts Handle Record Values During CSV Imports?
Explore how NetSuite user event scripts manage record values during CSV imports, specifically within the Before Submit and After Submit phases.
Short answer
During a CSV import, context.oldRecord is empty for new fields, and context.newRecord holds the imported value. If a field is modified in a Before Submit script using context.newRecord.setValue(), this new value will be reflected in context.newRecord during After Submit, potentially overriding the original imported data.
Scenario
A NetSuite user is performing a CSV import to update a Sales Order (SO) record. The import aims to populate an initially empty custom field with a new value, for example, 'abc'.
Solution
NetSuite user event scripts operate at different phases during record processing, primarily Before Submit and After Submit. While Before Load is also available, the focus for understanding record value changes during CSV imports is on the submit phases.Consider a scenario where a CSV import is executed on a Sales Order (SO) to update a custom field that is currently empty. The imported CSV provides a new value, such as 'abc', for this field.Field Values Without Modification in Before Submit* During the Before Submit phase:
- The context.oldRecord object for the field will be empty (e.g., '').
- The context.newRecord object for the field will contain the imported value (e.g., 'abc').* During the After Submit phase:
- The context.oldRecord object for the field will still be empty (e.g., '').
- The context.newRecord object for the field will contain the imported value (e.g., 'abc').Field Values With Modification in Before SubmitNow, consider the same CSV import, but a user event script is configured to modify the field's value during the Before Submit phase (e.g., to update it or concatenate with another value).* During the Before Submit phase:
- The context.oldRecord object for the field will be empty (e.g., '').
- The context.newRecord object for the field will contain the imported value (e.g., 'abc').
- If the script then sets the field's value using SuiteScript 2.x:
javascriptcontext.newRecord.setValue({fieldId: 'Field_Internal_ID', value: 'CCC'});- During the After Submit phase:
- The context.oldRecord object for the field will still be empty (e.g., '').
- The context.newRecord object for the field will now reflect the value set in the Before Submit script (e.g., 'CCC').It is crucial to exercise caution when modifying field values in Before Submit scripts during CSV imports. Such modifications can overwrite the data intended for import, potentially leading to data loss if not handled carefully.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
