我創建了一個名爲Margin的新交易列字段,並將其添加到銷售訂單。我編寫了一個腳本根據項目字段計算頁邊距,但如果您返回編輯這些值,則腳本不會重新計算。如何在用戶編輯值時重新計算它?Netsuite交易列字段重新計算
function postSourcing(type, name){
if(name == 'item'){
var unitPrice = nlapiGetCurrentLineItemValue('item','rate');
nlapiLogExecution('DEBUG', 'Price', + unitPrice);
var itemid = nlapiGetCurrentLineItemValue('item', 'item');
var avgCost = nlapiGetCurrentLineItemValue('item','lastpurchaseprice');
nlapiLogExecution('DEBUG', 'Cost', + avgCost);
var marginCalc = Math.round((((unitPrice - avgCost)/unitPrice)*100) * 10)/10;
nlapiLogExecution('DEBUG', 'Margin', + marginCalc);
nlapiSetCurrentLineItemValue('item','custcol9', marginCalc);
avgCost = Math.round(avgCost * 100)/100;
nlapiSetCurrentLineItemValue('item','lastpurchaseprice', avgCost);
var dollarPro = unitPrice - avgCost;
nlapiSetCurrentLineItemValue('item','custcoldollarprofit', dollarPro);
var itemQty = nlapiGetCurrentLineItemValue('item','quantity');
var extDollar = dollarPro * itemQty;
nlapiSetCurrentLineItemValue('item','custcolextdollarprofit',extDollar);
nlapiCommitLineItem('item');
}
}
非常感謝你解釋這個!我對Netsuite的腳本還不熟悉。 :)似乎現在工作正常。 – Laura 2014-10-13 13:43:55