Auto Numbered Lines

By - March 24, 2020

Line Auto-numbering

This recipe assigns unique, permanent numeric values to each line on a transaction. It is suitable for correlating lines between different transaction types. For example, if you have 10 lines on a Sales Order and fulfill lines 1, 3, and 5, you get an Item Fulfillment with three lines, numbered natively as 1, 2, 3. With this recipe, the unique number for lines 1, 3, and 5 on the SO will remain the same unique identifier on the Item Fulfillment even though the native line numbers differ.

For some transactions, NetSuite provides a lineuniquekey field, but for cases where that field is not available, this recipe can be handy.


Create a custom column field (named custcol_rsm_unique_line_number of type integer number and apply it to all the transaction types that you want autonumbered.
Note: todo: test more edge cases like deleting the first/last line.
Example using uniquely numbered InterCompanyTransferOrder item sublist lines.

export function beforeSubmit(context: EntryPoints.UserEvent.beforeSubmitContext) {
if (context.type === context.UserEventType.EDIT || context.type === context.UserEventType.CREATE) {
const newRecord = new InterCompanyTransferOrder(context.newRecord)
// only consider lines without line numbers - on CREATE that will be ALL the lines, on EDIT only added
// but we also need to consider deleted lines
// Get the Current Line Count Max value, else default to zero if no lines are populated
// note to handle deletions we get the max from the _old_ record
let max = _.max( ? new InterCompanyTransferOrder(context.oldRecord).item :
newRecord.item, 'custcol_rsm_unique_line_number')) || 0
// add numbers to lines without a value
.reject(i => i.custcol_rsm_unique_line_number)
.forEach(line => line.custcol_rsm_unique_line_number = ++max)
return 'Shazam, line numbers updated!'

Receive Posts by Email

Subscribe and receive notifications of new posts by email.