Search code examples
netsuitesuitescriptsuitescript1.0

Can't create item receipt in NetSuite using SuiteScript 1.0


So, i'm trying to create a Item Receipt on my NetSuite instance using SuiteScript 1.0, and i'm receiving this error message:

{\"success\":false,\"errorMessage\":\"\\nCode: SSS_INVALID_SUBLIST_OPERATION\\nDetails: You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.\"}"

So, i do not understand a lot of NetSuite, but i think static lists can't be modified. If that's the case, then how am i supposed to create a Item Receipt through SuiteScript if i can't add the items?

Below are my scripts, and the Postman Json request that i'm using:

SuiteScript:

function createItemReceipt(dataIn) {
    try {
        var record = nlapiCreateRecord('itemreceipt', {recordmode: 'dynamic'});
        record.setFieldValue('entity', dataIn.entity);
        
        for (var i = 0; i < dataIn.items.length; i++) {
            var item = dataIn.items[i];
            record.selectNewLineItem('item');
            record.setCurrentLineItemValue('item', 'item', item.itemId);
            record.setCurrentLineItemValue('item', 'quantity', item.quantity);
            record.commitLineItem('item');
        }
        var recordId = nlapiSubmitRecord(record, true, true);
        
        return {
            success: true,
            recordId: recordId
        };
    } catch (e) {
        return {
            success: false,
            errorMessage: e.toString()
        };
    }
}

function post(dataIn) {
    var response = createItemReceipt(dataIn);
    return JSON.stringify(response);
}

Json payload:

    {
      "entity": "123",
      "items": [
        {
          "itemId": "456",
          "quantity": 10
        },
        {
          "itemId": "789",
       

   "quantity": 5
    }
  ]
}

Solution

  • Item receipts in NetSuite are rarely, if ever, created as standalone records. The typical way they are created is to transform a purchase order, or a transfer order. To do this, use the nlapiTransformRecord(type, id, transformType, transformValues) instead of nlapiCreateRecord.

    The documentation for SS1.0 has been removed from SuiteAnswers HTML and packaged into a PDF reference. This can be found at https://{{accountid}}.app.netsuite.com/help/helpcenter/shared_resources/PDF/SuiteScript10API.pdf?whence=. Search in there for nlapiTransformRecord.

    I've partially reproduced the relevant section below, but the documentation has more, including examples - so look that up also if you can.

    nlapiTransformRecord(type, id, transformType, transformValues)

    Initializes a new record using data from an existing record of a different type and returns an nlobjRecord. This function can be useful for automated order processing such as creating item fulfillment transactions and invoices off of orders.

    This API is supported in client, user event, scheduled, and Suitelet scripts. See the help topic SuiteScript 1.0 API Governance for the unit cost associated with this API.

    For a list of supported transform types, see Supported Transformation Types.

    Parameters

    • type {string} [required] - The record internal ID name. In the NetSuite Help Center, see the help topic SuiteScript Supported Records. The internal ID appears in the column called “Record Internal ID”.

    • id {int} [required] - The internalId for the record, for example 555 or 78.

    • transformType {string} [required] - The record internal ID name of the record you are transforming the existing record into

    • transformValues {hashtable} [optional] - An array of field name -> value pairs containing field defaults used for transformation. Note that you can also specify whether you want the record transformation to occur in dynamic mode. For details, see the help topic SuiteScript 1.0 Working with Records in Dynamic Mode.