保存商品时,我试图检索和修改收货地址船运电话的价值,但是更改没有保存(而且我还没有弄清楚如何取回船运电话,因此我正在用电话价值进行初始测试)。还有另一种方法可以使我实际更新事务级地址详细信息吗?我假设我需要加载客户记录以获取地址,因为我无法直接在交易记录上获取电话,但这仍然无法解释我如何为交易的收货地址设置shipphone。
function beforeSubmit(context) {
var ifNum = 'N/A';
if (context.newRecord.id) ifNum = context.newRecord.id;
var recordPhone = context.newRecord.getValue('phone');
var phoneValid = checkPhone(recordPhone);
if (!phoneValid) {
try {
var correctedPhone = correctPhone(recordPhone);
var shipaddress = context.newRecord.getSubrecord('shippingaddress')
shipaddress.setValue({fieldId: 'shipphone', value: correctedPhone});
log.debug('Set phone to: ' + correctedPhone + ' from ' + recordPhone);
}
catch(e) {
var errorStr = 'Error setting IF #' + ifNum + ' phone value';
log.error(errorStr, e.message);
throw error.create({
name: errorStr,
message: e.message,
notifyOff: true
});
}
}
}
答案 0 :(得分:3)
shipphone
是具有交易记录的交易主体级别字段(销售订单,项目履行等)
其源自的地址子记录字段为addrphone
,因此您的代码应该更像:
var recordPhone = context.newRecord.getValue({fieldId:'shipphone'});
...
context.newRecord.setValue({fieldId:'shipphone', value:correctedPhone}); // for this transaction
shipaddress.setValue({fieldId: 'addrphone', value: correctedPhone}); // corrected for future uses of this address.