Reputation: 90
I'm creating a NetSuite invoice in dynamic mode with SuiteScript 2.0, and when I run commitLine on my first item, it errors with 'Please enter a value for amount.' even though I have already supplied it using setCurrentSublistValue.
The relevant section of code is START CREATING ITEM through FINISHED CREATING ITEM, but I've included the full restlet in case the problem is in my setup.
Here's the JSON data I'm using to generate the item:
{"item":26,"amount":5706.48,"custcol_unit_price":"7.863035405","quantity":725735,"description":"July Impressions - 2019 Digital (April-July) - Custom Affinity (CAF) Dynamic CPM 7.5","line":1}
I'm logging a call to getCurrentSublistValue immediately after the setter, to ensure the system is accepting the value I send, and get 5706.48 back out for amount, so I believe setCurrentSublistValue is inserting it.
/**
*@NApiVersion 2.x
*@NScriptType Restlet
*/
define(['N/record', 'N/error', 'N/log'],
function(record, error, log) {
function post(context) {
log.audit("invoice", context);
var rec = record.create({ type: "invoice", isDynamic: true });
for (var fldName in context) {
if (context.hasOwnProperty(fldName)) {
if (fldName === "trandate") {
rec.setValue(fldName, new Date(context[fldName]));
} else if (fldName === "items") {
var items = context[fldName]
for (var idx in items) {
var item = items[idx]
// START CREATING ITEM
log.audit('item', item)
rec.selectNewLine({ sublistId: 'item' });
for (var itemFldName in item) {
log.audit(itemFldName, item[itemFldName])
rec.setCurrentSublistValue({
sublistId: 'item',
fieldId: itemFldName,
value: item[itemFldName]
})
log.audit("current value", rec.getCurrentSublistValue({ sublistId: 'item', fieldId: itemFldName }))
}
rec.commitLine({ sublistId: 'item' });
// FINISHED CREATING ITEM
}
} else {
rec.setValue(fldName, context[fldName]);
}
}
}
var recordId = rec.save();
return { success: true, message: recordId }
}
return {
post: post
};
}
);
This is the error I'm seeing in the logs (line 34 is the commitLine call):
{"type":"error.SuiteScriptError","name":"USER_ERROR","message":"Please enter a value for amount.","stack":["anonymous(N/serverRecordService)","post(/SuiteScripts/api/submitInvoice.js:34)"],"cause":{"type":"internal error","code":"USER_ERROR","details":"Please enter a value for amount.","userEvent":null,"stackTrace":["anonymous(N/serverRecordService)","post(/SuiteScripts/api/submitInvoice.js:34)"],"notifyOff":false},"id":"","notifyOff":false,"userFacing":false}
Thanks in advance for any insight!
Upvotes: 1
Views: 8657
Reputation: 1
I had this issue and was able to fix it. The error states that there is a required field that needs to be filled out in order for the record to be saved. CAUSE: A workflow or script has made a field Mqndatory. FIX: Inactivate or Undeploy. Or add a Criteria that exempts that Transaction form from requiring that field to be Mandatory.
Upvotes: 0
Reputation: 8847
You are setting the Amount first, then the Quantity, and you are not setting the Rate. Because you are working with the record in Dynamic mode, you will need to set field values in the exact same order as you would in the UI, otherwise your data will be off.
If you need to continue working in Dynamic mode, then you will likely need to do a few things:
forceSyncSourcing
option of setCurrentSublistValue
to true
. This should ensure that any columns dependent on the Item are set correctly.I generally avoid this problem entirely by working in Standard mode instead of Dynamic. I have found it extremely rare that I need to work in Dynamic mode. In Standard mode, field order no longer matters as you let the server figure it out after you submit the entire record rather than in real-time as you set each field.
Upvotes: 4
Reputation: 2840
Try setting the quantity to 1. System might be overwriting your value with a calculated value of quantity * amount
when you commit the line.
Upvotes: 5