NetSuite客户端脚本字段已使用旧项值更改
我按照以下逻辑编写了一个简单的客户端脚本:一旦添加了一个新项目或将一个项目更改为一个新项目,毛利将自动计算并添加到该项目的相应字段中。我遇到的问题是fieldChanged给了我该项的旧(或未定义)子列表值,就好像它还没有更改一样。是否有方法告诉NetSuite,在项目更改后,等待其相应的子列表值更新,然后再使用fieldChanged填充值?谢谢NetSuite客户端脚本字段已使用旧项值更改,netsuite,suitescript,suitescript2.0,Netsuite,Suitescript,Suitescript2.0,我按照以下逻辑编写了一个简单的客户端脚本:一旦添加了一个新项目或将一个项目更改为一个新项目,毛利将自动计算并添加到该项目的相应字段中。我遇到的问题是fieldChanged给了我该项的旧(或未定义)子列表值,就好像它还没有更改一样。是否有方法告诉NetSuite,在项目更改后,等待其相应的子列表值更新,然后再使用fieldChanged填充值?谢谢 function fieldChanged(context) { var currentRecord = context.currentRe
function fieldChanged(context) {
var currentRecord = context.currentRecord;
var sublistName = context.sublistId;
var sublistFieldName = context.fieldId;
var line = context.line;
if (sublistName === 'item' && sublistFieldName === 'item'){
var costrateestimate = currentRecord.getCurrentSublistValue({sublistId: sublistName,fieldId: 'costestimaterate'});
var amount = currentRecord.getCurrentSublistValue({sublistId: sublistName,fieldId: 'amount'});
var quantity = currentRecord.getCurrentSublistValue({sublistId: sublistName,fieldId: 'quantity'});
var grossPerc = Math.round((1-(costrateestimate/amount*quantity))*100);
log.debug("Gross Margin Calculated = 100 - ("+costrateestimate+" / "+amount+" * "+currentRecord.getCurrentSublistValue({sublistId: sublistName,fieldId: 'quantity'})+") = "+grossPerc+"%");
currentRecord.setCurrentSublistValue({
sublistId: sublistName,
fieldId: 'custcol_gross_margin_perc',
value: grossPerc
});
}
}
明白了!我需要使用postSourcing入口点,而不是fieldChanged