【发布时间】:2020-03-30 08:02:50
【问题描述】:
在 NetSuite 中,我需要计算项目收据中的总金额(即行项目数量 x 行项目费率)。这在标准功能中不可用,因此需要编写脚本。
下面是客户端脚本 - 如果我们手动勾选行项目,它可以正常工作。但是,一旦我们在收据中使用标记全部或取消标记全部按钮,它就会被扭曲,因为不幸的是,这些按钮不会触发客户端脚本。我正在考虑在用户保存交易之前使用重新计算按钮来更正金额。有任何想法吗?
我也尝试过工作流操作脚本,但在首次创建/编辑事务时,重新计算按钮显示为灰色。非常感谢。
function fieldChng() {
var qty = nlapiGetCurrentLineItemValue('item', 'quantity');
var rate = nlapiGetCurrentLineItemValue('item', 'rate');
var total = qty * rate;
nlapiSetCurrentLineItemValue('item', 'custcol_ir_line_item_amount', total.toFixed(2), false);
//'custcol_ir_line_item_amount' is the internal id of Custom Transaction Line Field
}
function updateTotalAmount(type, name) {
// initialize variable for total amount
var totalAmount = 0;
// count number of lines in 'item' sublist
var itemCount = nlapiGetLineItemCount('item');
// for each line in the 'item' sublist, add value in amount column to
// the total amount variable
for (var i = 1; i <= itemCount; i++) {
lineLevelAmount = nlapiGetLineItemValue('item', 'custcol_ir_line_item_amount', i)
if (lineLevelAmount != '' && lineLevelAmount != null) {
totalAmount += parseFloat(lineLevelAmount);
}
}
// assuming custbody_ir_total_amount is the custom body field for the total
// amount, change its value based the value from the computation above
nlapiSetFieldValue('custbody_ir_total_amount', totalAmount.toFixed(2), false);
}
【问题讨论】:
-
当用户单击
Save按钮时,您可以使用客户端脚本中的saveRecord()入口点重新计算所有行项目。
标签: netsuite suitescript