如何在 SuiteScript 中获取和设置交易送货地址的送货电话?
How to get and set shipphone for transaction shipping address in SuiteScript?
我正在尝试检索和修改送货地址 shipphone 保存项目履行时的值,但更改没有保存(而且我还没有弄清楚如何检索 shipphone 所以我正在使用 phone 值进行初始测试)。有没有其他方法可以让我真正更新交易级别的地址详细信息?我假设我需要加载客户记录来获取地址,因为我无法直接在交易记录上获取 phone,但这仍然没有解释我如何为交易的送货地址。
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
});
}
}
}
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.
我正在尝试检索和修改送货地址 shipphone 保存项目履行时的值,但更改没有保存(而且我还没有弄清楚如何检索 shipphone 所以我正在使用 phone 值进行初始测试)。有没有其他方法可以让我真正更新交易级别的地址详细信息?我假设我需要加载客户记录来获取地址,因为我无法直接在交易记录上获取 phone,但这仍然没有解释我如何为交易的送货地址。
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
});
}
}
}
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.