我正试图从销售订单项中获得一些价值,但由于某种原因,我无法从销售订单项中获得数量承诺字段。
这是我正在使用的现有代码:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
define([
'N/log'
], function(
log
) {
const exports = {};
function afterSubmit(context) {
var newRecord = context.newRecord
switch (context.type) {
case context.UserEventType.CREATE:
return ;
case context.UserEventType.EDIT:
var payload = getSalesOrderItems(newRecord);
log.debug(payload);
break;
default:
throw 'Invalid event type';
}
}
exports.afterSubmit = afterSubmit;
return exports;
});
function getSalesOrderItems(salesRecord)
{
var items = [];
var itemLength = salesRecord.getLineCount({
sublistId : 'item'
});
if (itemLength === 0) throw 'Order does not have any valid item';
for (var index = 0; index < itemLength; index++) {
var item = {};
var itemId = salesRecord.getSublistValue({
sublistId: 'item',
fieldId: 'item',
line: index
});
try {
var itemRecord = record.load({
type: record.Type.SERIALIZED_INVENTORY_ITEM,
id: itemId,
});
} catch (ex) {
if (JSON.parse(ex).name == "SSS_RECORD_TYPE_MISMATCH") {
itemRecord = record.load({
type: record.Type.KIT_ITEM,
id: itemId,
});
}
}
if (!itemRecord) throw ('Item with id ' + itemId + ' does not exist');
item.sku = itemRecord.getValue('itemidorig');
item.quantity_committed = salesRecord.getSublistValue({
sublistId: 'item', fieldId: 'quantitycommitted', line: index
});
item.quantity = salesRecord.getSublistValue({
sublistId: 'item', fieldId: 'quantity', line: index
});
items.push(item)
return items;
}
}
这是当前结果。
{
[{
"sku":"EMOST00405",
"quantity":2
}]
}
这是我所期望的结果。
{
[{
"sku":"EMOST00405",
"quantity_committed": 1,
"quantity":2
}]
}
通过更新顺序触发事件时,它可以正常工作。 任何答复表示赞赏。
答案 0 :(得分:0)
您的代码似乎正确,但是如果您在当前表单上没有字段(可能在当前表单上隐藏/未添加),则NetSuite返回public ArrayList<String> doubleList(ArrayList<String> words) {
int currWordsSize = words.size();
for (int i = 0; i < currWordsSize; i++) {
int indexOfInterest = 2*i;
String currWord = words.get(indexOfInterest);
words.add(indexOfInterest+1, currWord);
}
return words;
}
。确保在当前正在使用的SO表单上添加并显示该字段,然后尝试再次运行代码。