Skip to Main Content

Developer Community

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

NetSuite - Sales Order Item Fulfillment

Paula SokolowiczMar 20 2024

I need to generate the Sales Order Item Fulfillment in NetSuite using a Restlet 2.0 script setting Serial Numbers for each required item.

My script is:

/**
 * @NApiVersion 2.x
 * @NScriptType Restlet
 */
define(['N/record', 'N/search'], function(record) {
    function createItemFulfillmentFromSalesOrder(wcOrderId, serialNumbers) {
        try {
            var salesOrder = record.load({
                type: record.Type.SALES_ORDER,
                id: wcOrderId,
                isDynamic: true
            });
            var itemFulfillment = record.transform({
                fromType: record.Type.SALES_ORDER,
                fromId: wcOrderId,
                toType: record.Type.ITEM_FULFILLMENT,
                isDynamic: true
            });
            var itemCount = itemFulfillment.getLineCount({ sublistId: 'item' });

            for (var i = 0; i < itemCount; i++) {
                var inventoryDetail = record.create({
                    type: record.Type.INVENTORY_DETAIL,
                    isDynamic: true
                });
                inventoryDetail.setValue({
                    fieldId: 'item',
                    value: salesOrder.getSublistValue({
                        sublistId: 'item',
                        fieldId: 'item',
                        line: i
                    })
                });
                inventoryDetail.selectNewLine({sublistId: 'inventoryassignment'});
                inventoryDetail.setCurrentSublistValue({
                    sublistId: 'inventoryassignment',
                    fieldId: 'quantity',
                    value: 1
                });
                inventoryDetail.setCurrentSublistValue({
                    sublistId: 'inventoryassignment',
                    fieldId: 'issueinventorynumber',
                    value: serialNumbers[i]
                });
                inventoryDetail.commitLine({ sublistId: 'inventoryassignment' });
                inventoryDetailId = inventoryDetail.save();

                itemFulfillment.selectLine({ line: i });
                itemFulfillment.setCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'inventorydetail',
                    value: inventoryDetail
                });
                itemFulfillment.commitLine({ sublistId: 'item' });
            }

            var fulfillmentId = itemFulfillment.save();
            return {
                success: true,
                fulfillmentId: fulfillmentId
            };
        } catch (error) {
            return error;
        }
    }

    return {
        get: function(params) {
            var wcOrderId = params.wcOrderId;
            var serialNumbers = params.serialNumbers;
            if (wcOrderId && serialNumbers) {
                serialNumbers = serialNumbers.split(',');
                return JSON.stringify(createItemFulfillmentFromSalesOrder(wcOrderId, serialNumbers));
            } else {
                return JSON.stringify({
                    success: false,
                    message: 'Missing parameters: wcOrderId and/or serialNumbers'
                });
            }
        }
    };
});

But I'm getting the error "You have entered an Invalid Field Value <serial number internal id> for the following field: issueinventorynumber".

The error isn't related to the Sales Order or the Serial Number. It should be an error in the creation of the Inventory Detail record or in setting the issueinventorynumber.

Comments
Post Details
Added on Mar 20 2024
0 comments
81 views