ANS-1112 · SUITESCRIPT DEVELOPMENT
How to Identify Item Options on a Sales Order in NetSuite SuiteScript 2.x
Accessing item option details on sales order sublists requires specific SuiteScript 2.x methods.
Short answer
To check for item options on a sales order, use SuiteScript 2.x's `record.load` to get the sales order record. Then, use `record.getSublistValue` on the 'item' sublist to retrieve the 'options' field for a specific line. Remember that SuiteScript 2.x uses 0-based indexing, and the 'options' field often returns an object requiring parsing.
Scenario
Users often need to programmatically inspect sales order items to determine if specific item options have been selected. This is crucial for custom validations, integrations, or reporting that depends on the configuration of items with custom options. Identifying the presence and values of these options requires specific SuiteScript methods.
Solution
The solution involves using SuiteScript 2.x functions to load the sales order record and then retrieve the 'options' field value for a specific item line. This approach replaces legacy SuiteScript 1.0 functions like nlapiLoadRecord and getLineItemValue with their modular SuiteScript 2.x equivalents.
Load the Sales Order Record:
Use the
record.loadfunction from theN/recordmodule. This function requires an object with thetypeandidof the record.
javascript
var salesOrderRecord = record.load({
type: record.Type.SALES_ORDER,
id: salesOrderId // Replace salesOrderId with the internal ID of the sales order
});Retrieve Item Options from a Specific Line:
Access the 'options' field from the 'item' sublist using
record.getSublistValue.
javascript
var itemOptions = salesOrderRecord.getSublistValue({
sublistId: 'item',
fieldId: 'options',
line: lineNumber // Replace lineNumber with the 0-based index of the item line
});Important Considerations for SuiteScript 2.x:
- Modular Approach: SuiteScript 2.x uses a modular approach, requiring
N/recordto be defined and passed as a parameter to your script's main function. - 0-Based Indexing: Sublist line indexing in SuiteScript 2.x starts at 0 (e.g., the first line is
line: 0), which differs from SuiteScript 1.0. - 'Options' Field Value: The 'options' field typically returns an object or a stringified JSON object containing the internal IDs and values of custom item options, rather than a direct simple value as might be implied by older SuiteScript 1.0 examples. Further parsing may be required to extract specific option values.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
