ANS-1757 · SUITESCRIPT DEVELOPMENT

How to Determine the Correct Package Sublist ID in NetSuite Item Fulfillments

Determine the correct package sublist ID in NetSuite Item Fulfillments, which varies based on the shipping method, particularly for legacy integrated solutions.

Short answer

The package sublist ID in NetSuite Item Fulfillments depends on the shipping method. For legacy integrated FedEx, it's 'packagefedex'; for legacy integrated UPS, it's 'packageups'. Otherwise, it's 'package'. Scripting logic is required to dynamically identify the correct sublist ID for package manipulation, especially when dealing with older shipping integrations.

Scenario

When working with NetSuite Item Fulfillments, developers and administrators often need to interact with the 'Packages' sublist programmatically. A common challenge arises because the internal ID of this sublist is not static; it changes based on the shipping method selected for the fulfillment. This variability requires dynamic identification of the correct sublist ID to ensure scripts and customizations function reliably across different shipping scenarios, particularly those involving legacy integrated shipping methods.

Solution

The internal ID of the Packages sublist in NetSuite Item Fulfillments is dynamic, varying based on the shipping method chosen. For implementations utilizing legacy integrated shipping methods, the sublist ID may be 'packagefedex' for FedEx, 'packageups' for UPS, or simply 'package' for other methods. To correctly identify and interact with the appropriate sublist, implement the following SuiteScript 2.x logic:

javascript
/**
 * @NApiVersion 2.x
 * @NModuleScope SameAccount
 */
define(['N/record', 'N/error'], function(record, error) {

    function getPackageSublistId(itemFulfillmentRecord) {
        var packageSublistSuffix = null;

        // The "package" sublist ID changes depending on the shipping method
        if (itemFulfillmentRecord.getLineCount({ sublistId: 'package' }) !== -1) {
            packageSublistSuffix = '';
        } else if (itemFulfillmentRecord.getLineCount({ sublistId: 'packagefedex' }) !== -1) {
            packageSublistSuffix = 'fedex';
        } else if (itemFulfillmentRecord.getLineCount({ sublistId: 'packageups' }) !== -1) {
            packageSublistSuffix = 'ups';
        } else {
            throw error.create({
                name: 'ERR_PACKAGE_SUBLIST_NOT_SUPPORTED',
                message: 'Package sublist must be "package", "packagefedex", or "packageups" for this record.'
            });
        }
        return 'package' + packageSublistSuffix;
    }

    function setTrackingNumberOnAllPackages(itemFulfillmentRecord) {
        var packageSublistId = getPackageSublistId(itemFulfillmentRecord);

        // Set the same tracking number on All packages on IF
        var packagesCount = itemFulfillmentRecord.getLineCount({ sublistId: packageSublistId });
        for (var lineIndex = 0; lineIndex < packagesCount - 1; lineIndex++) { // Loop iterates for lines 0 to packagesCount-2, skipping the last package as per original logic

            var trackingNumber = g_currentScdRecord.getFieldValue("custrecord_track_number");
            if (trackingNumber !== null && trackingNumber !== "") {
                itemFulfillmentRecord.setSublistValue({
                    sublistId: packageSublistId,
                    fieldId: "packagetrackingnumber" + (packageSublistId.includes('fedex') || packageSublistId.includes('ups') ? packageSublistId.replace('package', '') : ''),
                    line: lineIndex,
                    value: trackingNumber
                });
            }
        }
    }

    return {
        getPackageSublistId: getPackageSublistId,
        setTrackingNumberOnAllPackages: setTrackingNumberOnAllPackages
    };
});

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant