ANS-0450 · SUITESCRIPT DEVELOPMENT

How to Access Item Type and Subtype on NetSuite Transaction Line Items

Understand how to programmatically retrieve item type and subtype details from sublists on NetSuite transactions like Sales Orders and Purchase Orders.

Short answer

NetSuite transaction line items contain hidden fields for item type and subtype. These can be accessed programmatically using SuiteScript 2.1 functions like `record.getCurrentSublistValue` and `record.getSublistValue` to validate item specifics. Common values include 'NonInvtPart', 'Service', 'OthCharge', 'Kit', 'Assembly', and subtypes like 'Sale', 'Purchase', 'Resale'.

Scenario

Users need to access item type and subtype information from the items list on various NetSuite entities, such as Sales Orders or Purchase Orders. This data is crucial for validating item-specific logic or automating processes based on an item's classification.

Solution

The items list on NetSuite transaction entities, such as Sales Orders and Purchase Orders, contains hidden fields that provide access to an item's type and subtype. This information is valuable for implementing specific validations or logic based on item classification.

Common item type and subtype values include:

TYPE_NON_INVENTORY 'NonInvtPart'

TYPE_SERVICE 'Service'

TYPE_OTHERCHARGE 'OthCharge'

TYPE_KIT 'Kit'

TYPE_DESCRIPTION 'Description'

TYPE_ASSEMBLY 'Assembly'

SUB_TYPE_SALE 'Sale'

SUB_TYPE_PURCHASE 'Purchase'

SUB_TYPE_RESALE 'Resale'

Subtypes are applicable for Non-Inventory, Service, and Other Charge item types.

To programmatically access these values, NetSuite recommends using SuiteScript 2.1. The equivalent methods for retrieving item type and subtype from transaction line items are record.getCurrentSublistValue for the currently selected line and record.getSublistValue for a specific line number.

Example using record.getCurrentSublistValue (e.g., in a client script):

javascript
/**
 * @NApiVersion 2.1
 * @NModuleScope SameAccount
 */
define(['N/record'], function(record) {
    function pageInit(context) {
        var currentRecord = context.currentRecord;
        var itemType = currentRecord.getCurrentSublistValue({
            sublistId: 'item',
            fieldId: 'itemtype'
        });
        var itemSubType = currentRecord.getCurrentSublistValue({
            sublistId: 'item',
            fieldId: 'itemsubtype'
        });
        // Example: console.log('Current Item Type:', itemType, 'Subtype:', itemSubType);
    }
    return {
        pageInit: pageInit
    };
});

Example using record.getSublistValue (e.g., in a user event script or for a loaded record):

javascript
/**
 * @NApiVersion 2.1
 * @NModuleScope SameAccount
 */
define(['N/record'], function(record) {
    function afterSubmit(context) {
        var newRecord = context.newRecord;
        var lineCount = newRecord.getLineCount({ sublistId: 'item' });
        for (var i = 0; i < lineCount; i++) {
            var itemType = newRecord.getSublistValue({
                sublistId: 'item',
                fieldId: 'itemtype',
                line: i
            });
            var itemSubType = newRecord.getSublistValue({
                sublistId: 'item',
                fieldId: 'itemsubtype',
                line: i
            });
            // Example: console.log('Line', i, 'Item Type:', itemType, 'Subtype:', itemSubType);
        }
    }
    return {
        afterSubmit: afterSubmit
    };
});

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant