ANS-0388 · SUITESCRIPT DEVELOPMENT
How to Create Records with Line Items in NetSuite Client Scripts?
NetSuite's 2014.2 update introduced new requirements for adding sublist line items to records created via client-side scripts.
Short answer
To successfully add line items to a new record in a NetSuite client-side script, use `selectNewLineItem()` to initiate a new line. Then, set values for the line using `setCurrentLineItemValue()` for each field. Finally, commit the new line to the sublist with `commitLineItem()`. Failing to follow this sequence will result in an "undefined" error and uncreated lines.
Scenario
When attempting to create a new record and add line items using a client-side script, developers may encounter issues where line items are not properly saved. Prior to the NetSuite 2014.2 update, `setLineItemValue` could be used directly on new records. However, NetSuite now enforces additional rules, requiring a specific sequence of functions for sublist manipulation.
Solution
To correctly add new line items to a record within a client-side script, the following sequence of functions must be used:
Initiate the creation of a new line item using the
selectNewLineItemfunction.
selectNewLineItemSet the required values for the fields on the currently selected new line item using
setCurrentLineItemValue. This function should be called for each field on the line.
setCurrentLineItemValueCommit the newly configured line item to the record's sublist using the
commitLineItemfunction.
commitLineItemFailure to follow these steps will result in the line items not being created and an "undefined" error being thrown by NetSuite.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
