Muhammad Hafiz
07/19/2022, 6:39 AM"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
Any info on this error? I included my code and json in the replyMuhammad Hafiz
07/19/2022, 6:41 AM/**
* @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
});
inventoryAdjustment.selectNewLine({
sublistId: 'item'
});
var items = requestBody.items;
items.forEach(function (item) {
inventoryAdjustment.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: item.item_id
});
inventoryAdjustment.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: item.quantity
});
inventoryAdjustment.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'rate',
value: item.rate
});
inventoryAdjustment.commitLine({
sublistId: 'item'
});
});
try {
var id = inventoryAdjustment.save({
ignoreMandatoryFields: false
});
log.debug('record save with id', id);
return id;
} catch (e) {
return 0;
}
}
return {
post: doPost
};
});
Muhammad Hafiz
07/19/2022, 6:43 AM{
"account": 113,
"department": 102,
"adjlocation": 103,
"item": {
"items": [
{
"item": {
"id": 3569
},
"rate": 20000,
"quantity": 5
}
]
}
}
battk
07/19/2022, 7:09 AMbattk
07/19/2022, 7:09 AMMuhammad Hafiz
07/19/2022, 7:18 AMbattk
07/19/2022, 7:19 AMMuhammad Hafiz
07/19/2022, 7:21 AMMuhammad Hafiz
07/19/2022, 8:01 AMbattk
07/19/2022, 8:10 AMMuhammad Hafiz
07/19/2022, 8:38 AMinventoryAdjustment.selectNewLine({
sublistId: 'inventory'
});
var items = requestBody.items;
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);//sales order internal id
return id;
} catch (e) {
return 0;
}
}
Muhammad Hafiz
07/19/2022, 8:39 AMTypeError: Cannot read property \'forEach\' of undefined
battk
07/19/2022, 9:31 AMbattk
07/19/2022, 9:32 AMMuhammad Hafiz
07/19/2022, 9:38 AM{
"account": 113,
"department": 102,
"adjlocation": 103,
"inventory": {
"items": [
{
"item": 3569,
"rate": 20000,
"quantity": 5
}
]
}
}
battk
07/19/2022, 9:41 AMbattk
07/19/2022, 9:42 AMMuhammad Hafiz
07/19/2022, 10:09 AM"inventory": {
"currentline": {
"adjustqtyby": "",
"avgunitcost": "",
"costingmethod": "",
"cseg_brands": "",
"cseg_category": "",
"currency": "",
"currentvalue": "",
"custcol_itemcode": "",
"description": "",
"exchangerate": "1",
"foreigncurrencyunitcost": "",
"invtdiffvalue": "",
"item": "",
"label": "",
"labelcurrency": "",
"labelfxunitcost": "",
"line": "",
"location": "",
"memo": "",
"newquantity": "",
"quantityonhand": "",
"sys_id": "-3017117072737655",
"sys_parentid": "3017116882548740",
"unitconversionrate": "",
"unitcost": "",
"units": "",
"#": "2"
},
"line 1": {
"adjustqtyby": "20",
"avgunitcost": "100.00",
"costingmethod": "AVG",
"cseg_brands": "234",
"cseg_brands_display": "WYETH",
"cseg_category": "109",
"currency": null,
"currentvalue": "0.00",
"custcol_itemcode": "8886472103133",
"description": "S26 PROCAL GOLD 1600 GR",
"exchangerate": "1",
"foreigncurrencyunitcost": null,
"invtdiffvalue": "2000.00",
"item": "5660",
"item_display": "S26 PROCAL GOLD 1600 GR",
"line": "1",
"location": "103",
"memo": null,
"newquantity": "18",
"quantityonhand": "-2",
"sys_id": "3017116882588315",
"sys_parentid": "3017116882548740",
"unitconversionrate": "1",
"unitcost": "100.00",
"units": "1",
"units_display": "PCS"
}
},
Muhammad Hafiz
07/19/2022, 10:15 AMbattk
07/19/2022, 10:48 AMbattk
07/19/2022, 10:52 AMMuhammad Hafiz
07/19/2022, 12:07 PMMuhammad Hafiz
07/20/2022, 9:15 AM/**
* @NApiVersion 2.1
* @NScriptType Restlet
* @NModuleScope SameAccount
*/
define(['N/record'],
/**
* @param{record} record
*/
(record) => {
const post = (requestBody) => {
// Use create for new records
var newInvAdj = record.create({
type: record.Type.INVENTORY_ADJUSTMENT,
isDynamic: true,
});
newInvAdj.setValue('department', requestBody.department);
newInvAdj.setValue('adjlocation', requestBody.adjlocation);
newInvAdj.setValue('account', requestBody.account);
var line1 = {
'item': requestBody.item,
'location': requestBody.location,
'adjustqtyby': requestBody.adjustqtyby
};
newInvAdj.selectNewLine({
sublistId: 'inventory'
});
for (var field in line1) {
newInvAdj.setCurrentSublistValue({
sublistId: 'inventory',
fieldId: field,
value: line1[field]
});
}
newInvAdj.commitLine({
sublistId: 'inventory'
});
newInvAdj.save();
}
return { post: post }
});
When I use that code, I get an error : "name\":\"INVALID_FLD_VALUE\",\"message\":\"Field must contain a value.Muhammad Hafiz
07/20/2022, 9:17 AMvar line1 = {
'item': 3569,
'location': 1,
'adjustqtyby': 10
};
The code is workingMuhammad Hafiz
07/20/2022, 9:17 AM{
"department": 1,
"adjlocation": 103,
"account": 113,
"customer": 1075,
"inventory": {
"line1": {
"item": 3569,
"location": 103,
"adjustqtyby": 5
}
}
}
battk
07/20/2022, 9:19 AMbattk
07/20/2022, 9:19 AMbattk
07/20/2022, 9:21 AM