我目前有一个重新计算功能,如果订单项发生更改,它会重置运费字段,但我真的只需要在项目有重量时这样做。如何检索已更改订单项的权重?
这是我目前拥有的:
function recalc(){
nlapiSetFieldValue('shippingcost', '0.00');
}
我目前有一个重新计算功能,如果订单项发生更改,它会重置运费字段,但我真的只需要在项目有重量时这样做。如何检索已更改订单项的权重?
这是我目前拥有的:
function recalc(){
nlapiSetFieldValue('shippingcost', '0.00');
}
recalc
仅当对行项目的更改影响事务的总计时才会触发,因此对于您想要完成的事情可能不是一个可靠的事件。
我建议不要使用validateLine
,因为应该使用该事件来确定字段的新值是否有效。
我建议您使用它fieldChanged
来响应已更改的字段值。就像是:
function fieldChanged(type, name, linenum) {
if (type == 'item') {
if (name == 'item') {
handleItemChange(linenum);
}
}
}
function handleItemChange(linenum) {
var itemWeight = parseFloat(nlapiGetFieldValue('item', 'weight', linenum)) || 0;
if (itemWeight > 0) {
nlapiSetFieldValue('shippingcost', 0);
}
}
您可能还需要考虑postSourcing
event 而不是fieldChanged
,具体取决于哪些字段应该实际触发此逻辑。
小的 segue,recalc 并没有给你一种方法来获取子列表的当前行,你需要在任何时候循环遍历整个子列表。
试试 validateLine,类似:
function validateLine(listType){
//To get the item weight, you could create a
//custom transaction column field that sourced the item weight.
if(nlapiGetCurrentLineItemValue(listType,'custcolitemWeight') > 0){
nlapiSetFieldValue('shippingcost','0.00')
}
//or you could source directly from the item record using nlapiLookupField
// Depending on your use case either could be appropriate
if(nlapiLookupField('item',nlapiGetCurrentLineItemValue(listType,'item'),'weight')){
nlapiSetFieldValue('shippingcost','0.00')
}
//you *need* to return true with the validate* event functions.
return true;
}
这个(未经测试的)示例仅处理行添加。如果允许用户删除项目,您将需要实现一个类似的 validateDelete 来恢复您的更改。