使用 restlet 创建 NetSuite 发票时如何修复 'Please enter a value for amount.'?
How to fix 'Please enter a value for amount.' when creating NetSuite invoice with restlet?
我正在使用 SuiteScript 2.0 在动态模式下创建 NetSuite 发票,当我在第一个项目上 运行 commitLine 时,它出现 'Please enter a value for amount.' 错误,即使我已经使用 setCurrentSublistValue 提供了它.
代码的相关部分是从“开始创建项目”到“完成创建项目”,但我已经包含了完整的 restlet,以防我的设置出现问题。
这是我用来生成项目的 JSON 数据:
{"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}
我在 setter 之后立即记录了对 getCurrentSublistValue 的调用,以确保系统正在接受我发送的值,并返回 5706.48 以获得金额,所以我相信 setCurrentSublistValue 正在插入它。
/**
*@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
};
}
);
这是我在日志中看到的错误(第 34 行是 commitLine 调用):
{"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":假,"userFacing":假}
提前感谢您的任何见解!
尝试将数量设置为 1。当您提交该行时,系统可能会用 quantity * amount
的计算值覆盖您的值。
您是先设置金额,再设置数量,没有设置费率。因为您是在动态模式下处理记录,所以您需要按照与在 UI 中完全相同的顺序设置字段值,否则您的数据将会关闭。
如果您需要继续在动态模式下工作,那么您可能需要做一些事情:
- 通过将
setCurrentSublistValue
的 forceSyncSourcing
选项设置为 true
,确保在设置项目字段时发生采购。这应确保正确设置依赖于项目的任何列。
- 确保您以正确的顺序设置项目列;可能是项目,然后是数量,然后是金额。这样,动态模式应该不会重新计算您的金额。
我通常通过在标准模式而不是动态模式下工作来完全避免这个问题。我发现我很少需要在动态模式下工作。在标准模式下,字段顺序不再重要,因为您让服务器在您提交整个记录后计算出来,而不是在您设置每个字段时实时计算。
我正在使用 SuiteScript 2.0 在动态模式下创建 NetSuite 发票,当我在第一个项目上 运行 commitLine 时,它出现 'Please enter a value for amount.' 错误,即使我已经使用 setCurrentSublistValue 提供了它.
代码的相关部分是从“开始创建项目”到“完成创建项目”,但我已经包含了完整的 restlet,以防我的设置出现问题。
这是我用来生成项目的 JSON 数据:
{"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}
我在 setter 之后立即记录了对 getCurrentSublistValue 的调用,以确保系统正在接受我发送的值,并返回 5706.48 以获得金额,所以我相信 setCurrentSublistValue 正在插入它。
/**
*@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
};
}
);
这是我在日志中看到的错误(第 34 行是 commitLine 调用):
{"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":假,"userFacing":假}
提前感谢您的任何见解!
尝试将数量设置为 1。当您提交该行时,系统可能会用 quantity * amount
的计算值覆盖您的值。
您是先设置金额,再设置数量,没有设置费率。因为您是在动态模式下处理记录,所以您需要按照与在 UI 中完全相同的顺序设置字段值,否则您的数据将会关闭。
如果您需要继续在动态模式下工作,那么您可能需要做一些事情:
- 通过将
setCurrentSublistValue
的forceSyncSourcing
选项设置为true
,确保在设置项目字段时发生采购。这应确保正确设置依赖于项目的任何列。 - 确保您以正确的顺序设置项目列;可能是项目,然后是数量,然后是金额。这样,动态模式应该不会重新计算您的金额。
我通常通过在标准模式而不是动态模式下工作来完全避免这个问题。我发现我很少需要在动态模式下工作。在标准模式下,字段顺序不再重要,因为您让服务器在您提交整个记录后计算出来,而不是在您设置每个字段时实时计算。