ANS-0727 · SUITESCRIPT DEVELOPMENT

How to Access All Record Fields During NetSuite XEDIT Events in Before Submit

Understanding how NetSuite's 'xedit' event limits direct access to all record fields in 'beforeSubmit' user event scripts is crucial for robust script development.

Short answer

During 'xedit' events (inline editing, mass update, 'N/record.submitFields'), the 'newRecord' context only provides modified fields. To access unmodified fields in a 'beforeSubmit' script, developers must explicitly load the record or use 'N/search' or 'N/record.lookupFields' to retrieve their values, as 'newRecord' will not contain them.

Scenario

When a NetSuite record is modified via direct-list editing (DLE), a mass update, or the 'N/record.submitFields' function, the system triggers an 'xedit' event. In a 'beforeSubmit' user event script, developers may encounter situations where the 'newRecord' context does not provide access to all fields on the record, only those explicitly modified. This limitation requires a specific approach to retrieve the values of unmodified fields.

Solution

The 'xedit' event is triggered when a record is modified via direct-list editing (DLE), a Mass Update, or the 'N/record.submitFields' function. Unlike 'create' or 'edit' execution types, during an 'xedit' event, the 'newRecord' context (accessible via 'context.newRecord' in SuiteScript 2.0) does not provide access to all fields on the record. Developers can retrieve the list of available fields using 'context.newRecord.getFields()', which returns the IDs of fields such as the record's internal ID, type, and the specific fields that were modified. The values of fields present in this array can be fetched using 'context.newRecord.getValue({fieldId: 'fieldName'})'. To access values for fields not included in 'context.newRecord' during an 'xedit' event, it is necessary to explicitly load the record using 'N/record.load', perform a search using 'N/search', or use 'N/record.lookupFields'. It is important to note that field values retrieved through these methods will reflect the record's state *before* the current submission, as the script is executing in the 'beforeSubmit' context. The following conceptual code illustrates how to retrieve a field's value, accounting for the 'xedit' event's behavior in a SuiteScript 2.0 'beforeSubmit' user event script. This example assumes 'N/record' is defined in the script's 'define' statement (e.g., 'define(['N/record'], function(record) { ... })').

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant