Netsuite - 设置行项目值

Netsuite - Set Line Item Value

我想弄清楚如何根据项目字段上另一个字段的值设置自定义值项目。我没有收到任何错误,但它没有更改值。

代码如下:

function validatePOLineItem(type){
   if(type == 'item'){
     for (var i = 0; i <= nlapiGetLineItemCount('item'); i++) {
     // Get the value for amount on the item line
     var amount = nlapiGetCurrentLineItemValue('item', 'amount');
     // Get the value for the PO Amount on the item line
     var po_amount = nlapiGetCurrentLineItemValue('item', 'custcol_po_amount');
     // Set PO Amount equal to Amount on the item line
     nlapiSetCurrentLineItemValue('item', po_amount, amount);
    }
   }
}

您不能以编程方式操作 amount 字段。您需要改为修改数量或费率。如果您尝试申请折扣或类似的东西,那么我建议使用 NetSuite 的折扣商品或促销代码机制。

问题:如果只处理当前订单项,为什么需要循环?

建议的解决方案:如果你想实现它,你可以将 Rate 设置为 'custcol_po_amount' 但这只有在数量为 1 并且假设 'custcol_po_amount' 上的值是准确的情况下才有效.

这是客户端脚本还是用户事件脚本?如果它是部署在验证行事件上的客户端脚本,那么您不需要执行循环。由于每次添加一行时都会触发该功能。此外,您还需要添加 'return true' 作为要添加的行的最后一行。

您似乎遗漏了要设置的列名。此外,您只需要更新 "current" 行...

function validatePOLineItem(type){
  if(type == 'item'){
    var amount = nlapiGetCurrentLineItemValue('item', 'amount');
    nlapiSetCurrentLineItemValue('item', 'custcol_po_amount', amount);
  }
}