ANS-0632 · SUITESCRIPT DEVELOPMENT

How to Correctly Insert Lines in NetSuite Inventory Adjustments via Script?

Understanding the proper sequence of operations for programmatically adding lines to inventory adjustment records in NetSuite using SuiteScript.

Short answer

To successfully create and submit an inventory adjustment record via script, first ensure a new line is explicitly inserted into the sublist. Then, populate the values for that newly created line. Directly setting line item values without prior insertion will lead to submission errors.

Scenario

Users attempting to programmatically create or modify inventory adjustment records in NetSuite may encounter issues where the record cannot be submitted after setting line item values. This typically occurs when the script attempts to populate sublist fields on a line that has not yet been formally added to the record.

Solution

When programmatically creating or modifying an inventory adjustment record, attempting to set line item values directly without first inserting a new line will prevent the record from being submitted. The correct procedure is to first insert a new line into the sublist, and then populate the values for that newly created line.The general sequence of operations for adding a line is:

  1. Insert a new line into the inventory adjustment sublist.

  2. Set the required values for the fields on that newly inserted line.

  3. Commit the line to the record.For SuiteScript 2.x development, which is currently recommended by NetSuite, the process for client-side scripts involves using methods such as currentRecord.selectNewLine, currentRecord.setCurrentSublistValue, and currentRecord.commitLine. An example of this sequence would be:

currentRecord.selectNewLine({ sublistId: 'item' });currentRecord.setCurrentSublistValue({ sublistId: 'item', fieldId: 'item', value: itemId });currentRecord.setCurrentSublistValue({ sublistId: 'item', fieldId: 'location', value: locationId });currentRecord.setCurrentSublistValue({ sublistId: 'item', fieldId: 'adjustqtyby', value: quantity });currentRecord.commitLine({ sublistId: 'item' });

This ensures the line is properly established before its values are assigned, allowing for successful record submission.

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant