下面是将自定义字段设置为“已批准”时将报价转换为NetSuite中的SO的代码。如果自定义字段值为空,我可以删除该行。
关于用户编辑报价时我如何返回到报价并将自定义字段设置为“已批准”的任何新行转换的任何想法?
定义(['N / record'],
function(record) {
function afterSubmit(context) {
var quote = context.newRecord;
if ((context.type == context.UserEventType.EDIT) || (context.type == context.UserEventType.CREATE)) {
var approvedCount = quote.getLineCount({
sublistId: 'item'
});
for (var i = 0; i < approvedCount; i++) {
var approved = quote.getSublistValue({
sublistId: 'item',
fieldId: 'custom_field',
line: i
});
if (approved) {
var order = record.transform({
fromType: record.Type.ESTIMATE,
fromId: quote.id,
toType: record.Type.SALES_ORDER,
isDynamic: true
})
}
var orderLine = order.getLineCount({
sublistId: 'item'
});
for (var j = 0; j < orderLine; j++) {
var approved = quote.getSublistValue({
sublistId: 'item',
fieldId: 'custom_field',
line: j
});
var selectLine = order.selectLine({
sublistId: 'item',
line: i
})
order.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'custom_field',
value: approved
})
order.commitLine({
sublistId: 'item'
})
}
}
order.save();
}
}
return {
beforeLoad: beforeLoad,
beforeSubmit: beforeSubmit,
afterSubmit: afterSubmit
};
});
这更多是编程问题。在“批准的”范围之外不存在“无功订单”,您需要记录所有更改,然后再将其应用到“估算”,然后再保存,否则脚本将运行一段时间。