Search code examples
netsuitesuitescriptsuitescript2.0

Keep getting an error when trying to submit an Inbound Shipment via Netsuite Restlet


I keep getting the following error when trying to create a new Inbound Shipment record (new in Netsuite).

{"type":"error.SuiteScriptError","name":"USER_ERROR","message":"Please enter value(s) for: Item","stack":["anonymous(N/recordService)","<anonymous>(/SuiteScripts/KK_Sandbox_Scripts_SD/RestLets/InboundShipment.js:132)","<anonymous>(/SuiteScripts/KK_Sandbox_Scripts_SD/RestLets/InboundShipment.js:99)","doPost(/SuiteScripts/KK_Sandbox_Scripts_SD/RestLets/InboundShipment.js:34)"],"cause":{"type":"internal error","code":"USER_ERROR","details":"Please enter value(s) for: Item","userEvent":null,"stackTrace":["anonymous(N/recordService)","<anonymous>(/SuiteScripts/KK_Sandbox_Scripts_SD/RestLets/InboundShipment.js:132)","<anonymous>(/SuiteScripts/KK_Sandbox_Scripts_SD/RestLets/InboundShipment.js:99)","doPost(/SuiteScripts/KK_Sandbox_Scripts_SD/RestLets/InboundShipment.js:34)"],"notifyOff":false},"id":"","notifyOff":false} 

Here is the code I have to set the record. I have verified that the sublist id is "items" and the fieldId is "itemid", but when I try to add the line, I get the above error.

function doPost(restletBody){
log.debug('Called from POST', restletBody);

var success = [],
errors = [];

restletBody.data.forEach(function(e) 
{
    try 
    {
        log.debug('Called from POST', e.id);

        //Create a new record
        var rec =
            r.create({
                type: "inboundshipment",
                isDynamic: true,
                defaultValues: null
            }).setValue({
                fieldId: "externalid",
                value: e.id,
                ignoreFieldChange: false
            });

        var i = 1;

    e.lineitems.items.forEach(function(item)
        {
            log.debug("Inside Line Items", item.itemid + " " + item.purchaseorder);


            rec.selectNewLine({sublistId:"items"});

            var field = rec.getSublistFields({
                sublistId: 'items'
            });

            rec.setCurrentSublistValue({
                sublistId: "items",
                fieldId: "purchaseorder",
                value: item.purchaseorder,
                ignoreFieldChange: true
            });

            rec.setCurrentSublistValue({
                sublistId: "items",
                fieldId: "itemid",
                value: item.itemid,
                ignoreFieldChange: true
            });
            log.debug("Inside Line Items", "ITEM Added " + item.itemid );

            rec.commitLine({sublistId:"items"});
            log.debug("Inside Line Items", "Line Committed" );

            ++i;
        });

        rec.save();
    }
    catch(err) 
    {
        var msg = '';
        log.debug("There was an error", err);
    }
})
return "";

}

I have tried changing the itemid to shipmentitem and id, and it doesn't work. Before, I was getting an error for PO, too, and it was because the name was wrong, but I fixed that (I believe) for the item.

One thing that might be affecting it (not sure) is that the PO list filters the item list. once the user selects the PO in the UI, it will filter the item list to only items on that PO. I have double-checked that the item I am trying to submit belongs to the PO I am trying to submit, but still receiving an error. Any ideas?


Solution

  • According to the NetSuite Record Browser, the field should be 'shipmentitem'.

    rec.setCurrentSublistValue({
        sublistId: "items",
        fieldId: "shipmentitem",
        value: item.itemid,
        ignoreFieldChange: true
    });
    

    EDIT: Updated to reflect that the fieldname should be 'shipmentitem' as @shawleigh17 discovered so future users find the correct answer.