我希望能够根据发货位置计算销售订单上项目的总重量,并将值存储在自定义字段中。在提交此脚本之前,我创建了一个。“自定义”字段设置为“十进制数”类型,并选中“存储值”框,但“销售订单”页面上的字段下未显示任何内容。
function calculateWeight(type){
var lines = nlapiGetLineItemCount('item');
var totalWeight2 = 0 ;
var totalWeight1 = 0 ;
if (lines >0){
for(var i = 1; i<= lines ; i++){
var location = nlapiGetLineItemValue('item','location', i);
var quantitycommitted = nlapiGetLineItemValue('item','quantitycommitted', i);
var weight = nlapiGetLineItemValue('item','custcol_individual_weight', i);
//var com_wgt = nlapiGetLineItemValue('item','custcol1',i);
if (location === '2'){
var total2 = weight * quantitycommitted;
totalWeight2 += total2 ;
}
if (location === '1'){
var total1 = weight * quantitycommitted;
totalWeight1 += total1 ;
}
}
nlapiSetFieldValue('custbody5', totalWeight1);
nlapiSetFieldValue('custbody4', totalWeight2);
}
}
我仍在学习SuiteScript,我不确定哪里出了问题。。。有人能帮忙吗?
更新的代码,仅适用于部分订单。。。
function calculateWeight(type){
var lines = nlapiGetLineItemCount('item');
//nlapiLogExecution('DEBUG', 'Number of lines', lines);
var totalWeight2 = 0 ;
var totalWeight1 = 0 ;
if (lines >0){
for(var i = 1; i<= lines ; i++){
var location = nlapiGetLineItemValue('item','location', i);
//nlapiLogExecution('DEBUG', 'Locations', location);
var quantitycommitted = parseInt(nlapiGetLineItemValue('item','quantitycommitted', i),10) || 0;
//nlapiLogExecution('DEBUG', 'QtyCom', quantitycommitted);
var weight = parseFloat(nlapiGetLineItemValue('item','custcol_individual_weight', i)) ||0;
//nlapiLogExecution('DEBUG', 'Wgt', weight);
//var com_wgt = nlapiGetLineItemValue('item','custcol1',i);
if (location == '2'){
var total2 = weight * quantitycommitted;
totalWeight2 += total2 ;
nlapiLogExecution('DEBUG', 'Total2', totalWeight2);
}
if (location == '1'){
var total1 = weight * quantitycommitted;
totalWeight1 += total1 ;
nlapiLogExecution('DEBUG', 'Total1', totalWeight1);
}
}
nlapiSetFieldValue('custbody_ms_weight_ppt_page', totalWeight1);
nlapiSetFieldValue('custbody_wi_weight_ppt_page', totalWeight2);
}
}