Search code examples
netsuitetransferinventory

Netsuite - Transfer Inventory error


I have been using NetSuite for only a short time, and already hate it. I am sorry if this is a stupid question, but I haven't been able to find an answer so far, either in the Netsuite docs, StackOverflow or other websites. In fact, the answers I found have resulted in an error.

My company requires a script to transfer inventory based on an EDI input file. Reading the file is no problem, even parsing it is working. However, actually inserting the data is proving problematic. I have been able to insert normal records, but Inventory Transfer records are giving me problems.

From Stack Overflow I found and adapted some code into the following:

var xfer = nlapiCreateRecord("inventorytransfer");

xfer.setFieldValue("trandate", FormatDate("20160101"));
xfer.setFieldValue("location", 9);
xfer.setFieldValue("transferlocation", 9);

nlapiSelectNewLineItem('invt');
nlapiSetLineItemValue("invt","invtid",1, 189);
nlapiSetLineItemValue("invt","adjustqtyby", 1, "5");
nlapiCommitLineItem('invt');

var id = nlapiSubmitRecord(xfer);

The FormatDate function just exchanges the date from the text file into a system date NetSuite can understand.

However, when I run this code I get the following error:

USER_ERROR: You must enter at least one line item for this transaction.

I thought inserting the line item was the reason to use nlapiSelectNewLineItem, but I guess not. Also nlapiCreateNewLineItem doesn't seem to exist.

The values I am inserting are all just test data, as I'm testing this in the debugger. Location 9 exists, as does item 189. My full script finds these id's based on string values from the text files. But since this is the section that doesn't work I have set it apart to test.

Can anyone help with this?


Solution

  • You did not specify the type of script you are using, but, looks like you are not setting the fields on the record object, but, setting the value on current record. Below, is the suggested code.

    Also, there is no sublist named invt, it should be inventory. Also, there is no field as such invtid, I think most probably you want to setup item, the field Id should be item. You might want to refer SuiteScript Record Browser as well for a help on correct Ids

    var xfer = nlapiCreateRecord("inventorytransfer");
    
    xfer.setFieldValue("trandate", FormatDate("20160101"));
    xfer.setFieldValue("location", 9);
    xfer.setFieldValue("transferlocation", 9);
    
    xfer.selectNewLineItem('inventory');
    xfer.setCurrentLineItemValue("inventory", "item", 189);
    xfer.setCurrentLineItemValue("inventory","adjustqtyby", "5");
    xfer.commitLineItem('inventory');
    
    var id = nlapiSubmitRecord(xfer);
    

    If you are using Bin/Lot Numbered Items, please see help topic "Sample Scripts for Advanced Bin / Numbered Inventory Management"