ANS-1268 · SUITESCRIPT DEVELOPMENT
How to Access Multi-select Field Values in SuiteScript 2.0 Xedit Context?
When working with multi-select fields in SuiteScript 2.0 user event scripts during an xedit operation, their values may be returned as a single string requiring special handling.
Short answer
In SuiteScript 2.0 user event scripts, when a multi-select field is updated via xedit, its value is often returned as a string with elements separated by the unicode character u0005. To correctly process these values, developers must explicitly split the string using this delimiter to convert it into an array for further manipulation.
Scenario
Developers working with SuiteScript 2.0 user event scripts may encounter an inconsistency when attempting to retrieve values from multi-select fields during an xedit operation. Unlike typical record contexts where multi-select values are returned as an array, in xedit, the system may return these values as a single string.
Solution
To correctly handle multi-select field values in a SuiteScript 2.0 user event script during an xedit operation, developers must account for the possibility that the value will be returned as a string rather than an array. This string will have its individual selections separated by the unicode character u0005. The following code snippet demonstrates how to retrieve and process such a field:
javascriptvar linkField = options.newRecord.getField({ fieldId: 'custbody_gs_comm_link'});var linkIds = options.newRecord.getValue({fieldId: 'custbody_gs_comm_link'});if(linkField.type == 'multiselect') { // In xedit, it is likely that the result will be return as a string separated by // the /u0005 character instead of an array, so we'll need to fix that. if(utilModule.isString(linkIds)) { linkIds = linkIds.split('u0005'); }} else { linkIds = [linkIds];}It is crucial to exercise caution when working with multi-select fields and xedit operations within user event scripts due to these potential inconsistencies.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
