Reputation: 25928
Why, when I attempt to create an Inventory Adjustment I get the error:
You have entered an Invalid Field Value 12112 for the following field: customer
I can confirm that that customer entity id is valid and that they are part of the correct subsidiary.
Any ideas what the heck is going wrong and how I can create a simple Inventory Adjustment?
require(['N/ui/serverWidget',
'N/email',
'N/runtime',
'N/search',
'N/file',
'N/config',
'N/format',
'N/record',
'N/log',
'N/runtime'],
function(ui, email, runtime, search, file, config, format, record, log, runtime) {
// Attempt to create an IA
var ia = record.create({
type: record.Type.INVENTORY_ADJUSTMENT,
isDynamic: true
});
// Set IA fields
var values = {
// 'entity': '12112', // Dummy customer
'customer': '12112',
'subsidiary': '2',
'account': '307',
'class': '36',
//'adjlocation': '2'
};
for (var key in values) {
ia.setValue({
fieldId: key,
value: values[key]
});
}
// Set IA Inventory sublist fields/lines
var line1 = {
'item': '61',
'location': '1',
'adjustqtyby': '-1',
'department': '3',
'class': '36',
};
ia.selectNewLine({
sublistId: 'inventory'
});
for (var field in line1) {
ia.setCurrentSublistValue({
sublistId: 'inventory',
fieldId: field,
value: line1[field]
});
}
ia.commitLine({
sublistId: 'inventory'
});
var recordId = ia.save({
enableSourcing: false,
ignoreMandatoryFields: false
});
var x = 0; // Add breakpoint for NS Debugger
});
Upvotes: 0
Views: 2381
Reputation: 3783
You are creating the record in "dynamic" mode, so you need to set fields in the same order as you would in the UI. In particular, you need to select a subsidiary
before you can set the customer
field.
Swapping these order of these two lines will most probably solve your error.
var values = {
// 'entity': '12112', // Dummy customer
'subsidiary': '2',
'customer': '12112',
'account': '307',
'class': '36',
//'adjlocation': '2'
};
However, take note that for..in
does not guarantee that it will follow any particular order, so theoretically NetSuite could push an update to their JavaScript engine at any time that would order things differently and break your code.
Upvotes: 1