ANS-0783 · SUITESCRIPT DEVELOPMENT
Why Sublist Fields Do Not Source in NetSuite Before Submit User Event Scripts?
Understand why sublist field sourcing does not occur during 'Before Submit' user event scripts, impacting real-time calculations.
Short answer
In NetSuite 'Before Submit' user event scripts, sublist fields are not fully sourced until the record is actually submitted. This means that setting a field like 'Tax Code' on a sublist will not immediately trigger the sourcing of dependent fields, such as tax rates, for real-time calculations within the same script execution.
Scenario
A NetSuite user event script attempts to set a sublist field, such as the Tax Code, within a 'Before Submit' context. The expectation is that dependent fields, like tax rates, would be automatically sourced and populated immediately after the Tax Code is set. However, these sourced fields remain blank, preventing subsequent calculations based on the expected sourced values.
Solution
When working with sublist fields in NetSuite user event scripts, particularly within a 'Before Submit' context, it is crucial to understand the timing of field sourcing. While setting sublist field values in SuiteScript 2.x using functions such as Record.setCurrentSublistValue involves parameters that control synchronous behavior, NetSuite's documentation clarifies that in server scripts (like user event scripts), this synchronous execution is always effectively true. This ensures predictable script execution. However, this synchronous execution does not mean that all dependent fields on a sublist will be immediately sourced and populated. NetSuite support confirms that for 'Before Submit' user event scripts, the full sourcing of sublist fields only occurs once the record has been actually submitted. Therefore, if a script sets a field like 'Tax Code' on a sublist, any fields that would typically be sourced based on that change (e.g., tax rates) will not be populated and available for immediate use within the same 'Before Submit' script execution. Calculations on line items that rely on these sourced values cannot be reliably performed at this stage. Developers should consider performing such calculations in an 'After Submit' user event script, where all fields have been fully sourced, or implement custom logic to retrieve necessary values.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
