【发布时间】:2019-08-29 18:16:21
【问题描述】:
我正在使用 SuiteScript 2.0 在动态模式下创建 NetSuite 发票,当我对我的第一个项目运行 commitLine 时,它会出现“请输入金额值”的错误。即使我已经使用 setCurrentSublistValue 提供了它。
相关的代码部分是从 START CREATING ITEM 到 FINISHED CREATING ITEM,但我已经包含了完整的 restlet,以防问题出在我的设置中。
这是我用来生成项目的 JSON 数据:
{"item":26,"amount":5706.48,"custcol_unit_price":"7.863035405","quantity":725735,"description":"7 月展示次数 - 2019 年数字版(4 月至 7 月) - 自定义关联度 (CAF ) 动态每千次展示费用 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":"请输入金额的值。","stack":["anonymous(N/serverRecordService)", "post(/SuiteScripts/api/submitInvoice.js:34)"],"cause":{"type":"internal error","code":"USER_ERROR","details":"请输入金额值.","userEvent":null,"stackTrace":["anonymous(N/serverRecordService)","post(/SuiteScripts/api/submitInvoice.js:34)"],"notifyOff":false},"id" :"","notifyOff":false,"userFacing":false}
提前感谢您的任何见解!
【问题讨论】:
-
我刚刚尝试在金额前添加一个美元符号,这会将错误更改为:“您为以下字段输入了无效的字段值 $5706.48:金额”
标签: netsuite invoice suitescript2.0