ANS-1602 · CUSTOM FIELDS, RECORDS & FORMS
How to Automatically Set the External ID Field on NetSuite Records During Create and Edit
Leverage an afterSubmit user event script to populate the external ID, ensuring proper record ID availability for updates.
Short answer
To automatically set the External ID field on NetSuite records during creation and editing, an `afterSubmit` user event script is required. This is because the record ID is not available in `beforeSubmit` for new records, preventing direct updates to `externalid`. The `afterSubmit` script can then load the record, set the `externalid` using `record.setValue()`, and save the changes with `record.submitFields()`.
Scenario
Users often expect to automatically populate the External ID field on NetSuite records by copying another field, such as UPC, using a `beforeSubmit` user event script during record creation or editing. However, the External ID field behaves uniquely, and a direct update in `beforeSubmit` is not feasible, particularly because the record ID is not yet available for new records.
Solution
Directly setting the externalid field using record.setValue('externalid', UPC) within a beforeSubmit user event script is not effective. This limitation arises because the externalid field cannot be directly set in beforeSubmit, especially during a record's creation event, as the record ID is not yet available. The recommended and effective solution is to implement an afterSubmit user event script for both create and edit events. This ensures the record ID is available, allowing for the necessary update.nn
In the
afterSubmituser event script, load the current record.nSet the
externalidfield to the desired value (e.g.,UPC) usingrecord.setValue('externalid', UPC).nPersist the changes by submitting the record using
record.submitFields.
Expert NetSuite Support
Need help with this NetSuite issue?
Custom Fields, Records & Forms consulting and configuration support
