I want to ask about Restlet in Netsuite. I try to use it to post to Inventory Adjustment but cant find how to work with it. Here is my code :
/**
* @NApiVersion 2.1
* @NScriptType Restlet
* @NModuleScope SameAccount
*/
define([
'N/record',
], function (record) {
function doPost(requestBody) {
log.debug('Post body', requestBody);
var inventoryAdjustment = record.create({
type: record.Type.INVENTORY_ADJUSTMENT,
isDynamic: true
});
var account = inventoryAdjustment.account;
var department = inventoryAdjustment.department;
var adjlocation = inventoryAdjustment.adjlocation;
inventoryAdjustment.setValue({
fieldId: 'account',
value: account
});
inventoryAdjustment.setValue({
fieldId: 'department',
value: department
});
inventoryAdjustment.setValue({
fieldId: 'adjlocation',
value: adjlocation
});
inventoryAdjustment.selectNewLine({
sublistId: 'inventory'
});
var items = requestBody.line;
items.forEach(function (inventory) {
inventoryAdjustment.setCurrentSublistValue({
sublistId: 'inventory',
fieldId: 'item',
value: inventory.item //internal id
});
inventoryAdjustment.setCurrentSublistValue({
sublistId: 'inventory',
fieldId: 'quantity',
value: inventory.quantity
});
inventoryAdjustment.setCurrentSublistValue({
sublistId: 'inventory',
fieldId: 'rate',
value: inventory.rate //custom in netsuite
});
inventoryAdjustment.commitLine({
sublistId: 'inventory'
});
});
try {
var id = inventoryAdjustment.save({
ignoreMandatoryFields: false
});
log.debug('record save with id', id);
return id;
} catch (e) {
return 0;
}
}
return {
post: doPost
};
});
When I try to run this code in Postman, there's an error that said :
"TypeError: Cannot read property \'forEach\' of undefined [at Object.doPost (/SuiteScripts/restlet_invadj.js:42:3)]"
My json to post look like this :
{
"account":113,
"department":102,
"adjlocation":103,
"inventory":{
"currentline":
{
"item":3569,
"rate":20000,
"quantity":5
}
}
}
I want to use the Restlet to integrate Netsuite with POS app. Any help is really appreciated, thank you.