Archive for the 'netsuite' Category

SuiteScript: Inventory Transfer via Code

Pre 2009.2, transferring inventory quantity from one location to another via SuiteScript can only be done through inventoryadjustment. First you have to add quantity to destination location.

xfer.setLineItemValue("inventory", "item", 1, ITEM_ID);
xfer.setLineItemValue("inventory", "location", 1, LOC_DESTINATION);
xfer.setLineItemValue("inventory", "adjustqtyby", 1, "5");

Then you have to deduct the quantity from the origin location

xfer.setLineItemValue("inventory", "item", 2, ITEM_ID);
xfer.setLineItemValue("inventory", "location", 2, LOC_ORIGIN);
xfer.setLineItemValue("inventory", "adjustqtyby", 2, "-5");

Putting it all together, the code will roughly look like this:

Continue reading ‘SuiteScript: Inventory Transfer via Code’

Show Field’s Internal ID

NetSuite’s Field Help is a small pop-up window that displays a brief description of the field associated to it. To open it, simply click the field label.

internal-id-01

Continue reading ‘Show Field’s Internal ID’

New Implementation of nlapiStringToDate in 2009.2

All of a sudden, our users complained that one of our NetSuite process failed. They reported this error:

TypeError: Cannot call method “getTime” of null (some_code.js$sys#791)

I tried to debug the code using nlapiLogExecution can still couldn’t locate where the error occured. I up the ante by using the script debugger and found that the error happens because the code is trying to call the getTime of a null object. Pretty self explanatory, but why did it happen? The code roughly looks like this:

var billDateStr = rec.getFieldValue("custrecord_billdate")
var billDate = nlapiStringToDate(billDateStr);
var billTime = billDate.getTime();

Continue reading ‘New Implementation of nlapiStringToDate in 2009.2′