NetSuite:启用订单项运输 (MSR) 时的自定义地址字段
NetSuite: Custom Address Fields when Line Item Shipping (MSR) is Enabled
我对 NetSuite 有一个古怪的问题。在已选中 'Enable Line Item Shipping' 的销售订单上,意味着启用了多条运输路线,运输地址位于项目行级别。
通过 SuiteScript,如果地址是从地址簿中选择的,我可以访问线路级别的地址。
但是,当该地址是动态输入的自定义地址时,我不知道如何在 beforeSubmit 函数中访问这些字段。
如有指点,将不胜感激!
您可以使用其中一个或以下两个来获取所选地址的详细信息
nlapiGetLineItemValue('item','shipaddress',1)
nlapiGetLineItemText('item','shipaddress',1)
以上只会给你地址记录的id,或标签。但是,很难在客户端访问地址详细信息。
但是,使用子记录 API,您可以使用子记录 API 在用户事件脚本中访问服务器端的记录:
var record = nlapiLoadRecord('customer', nlapiGetFieldValue('entity'),{recordmode: 'dynamic'});
//loop through all the addressbooks
if(record.getLineItemValue('addressbook', 'internalid', i) === nlapiGetLineItemValue('item','shipaddress', 1))
record.selectLineItem('addressbook', 2);
//change the sub record value
var subrecord = record.editCurrentLineItemSubrecord('addressbook', 'addressbookaddress');
subrecord.setFieldValue('attention', 'Accounts Payable');
subrecord.commit();
record.commitLineItem('addressbook');
var x = nlapiSubmitRecord(record);
想通了!致未来来此冒险的迷途者:
您可以在销售订单行级别使用下面的函数来遍历自定义地址并提取特定信息。
希望这会在某个时候添加到 NetSuite 文档中。
请注意,我这样做是专门为状态信息做的。如果您想查看其他可用字段,请将 &xml=T
添加到已提交的销售订单 URL 的末尾,然后在结果 xml 结构中搜索 iladdrbook
。它实际上被视为订单项。
function getCustomAddressFromLineItem(soLineNum) {
nlapiLogExecution('DEBUG', 'Custom Address', 'Custom Address: Line # ' + soLineNum);
var addressid = nlapiGetLineItemValue('item','shipaddress',soLineNum); // get the id of the custom address
var customAddressesLineCount = nlapiGetLineItemCount('iladdrbook'); // get custom address book count
nlapiLogExecution('debug', 'test', 'addressid: ' + addressid + ' -- linecount: ' + customAddressesLineCount);
for (var i = 1; i <=customAddressesLineCount; i++)
{
var addressinternalid = nlapiGetLineItemValue('iladdrbook','iladdrinternalid',i); // get internal id of custom address book
if (addressinternalid == addressid) // match it with the id of custom address being set
{
var addr = nlapiGetLineItemValue('iladdrbook','iladdrshipaddr1',i);
var customState = nlapiGetLineItemValue('iladdrbook','iladdrshipstate',i); // get your state
nlapiLogExecution('debug', 'test', 'address: ' + addr + ' -- state: ' + customState);
return customState;
}
}
}
我对 NetSuite 有一个古怪的问题。在已选中 'Enable Line Item Shipping' 的销售订单上,意味着启用了多条运输路线,运输地址位于项目行级别。
通过 SuiteScript,如果地址是从地址簿中选择的,我可以访问线路级别的地址。
但是,当该地址是动态输入的自定义地址时,我不知道如何在 beforeSubmit 函数中访问这些字段。
如有指点,将不胜感激!
您可以使用其中一个或以下两个来获取所选地址的详细信息
nlapiGetLineItemValue('item','shipaddress',1)
nlapiGetLineItemText('item','shipaddress',1)
以上只会给你地址记录的id,或标签。但是,很难在客户端访问地址详细信息。
但是,使用子记录 API,您可以使用子记录 API 在用户事件脚本中访问服务器端的记录:
var record = nlapiLoadRecord('customer', nlapiGetFieldValue('entity'),{recordmode: 'dynamic'});
//loop through all the addressbooks
if(record.getLineItemValue('addressbook', 'internalid', i) === nlapiGetLineItemValue('item','shipaddress', 1))
record.selectLineItem('addressbook', 2);
//change the sub record value
var subrecord = record.editCurrentLineItemSubrecord('addressbook', 'addressbookaddress');
subrecord.setFieldValue('attention', 'Accounts Payable');
subrecord.commit();
record.commitLineItem('addressbook');
var x = nlapiSubmitRecord(record);
想通了!致未来来此冒险的迷途者:
您可以在销售订单行级别使用下面的函数来遍历自定义地址并提取特定信息。
希望这会在某个时候添加到 NetSuite 文档中。
请注意,我这样做是专门为状态信息做的。如果您想查看其他可用字段,请将 &xml=T
添加到已提交的销售订单 URL 的末尾,然后在结果 xml 结构中搜索 iladdrbook
。它实际上被视为订单项。
function getCustomAddressFromLineItem(soLineNum) {
nlapiLogExecution('DEBUG', 'Custom Address', 'Custom Address: Line # ' + soLineNum);
var addressid = nlapiGetLineItemValue('item','shipaddress',soLineNum); // get the id of the custom address
var customAddressesLineCount = nlapiGetLineItemCount('iladdrbook'); // get custom address book count
nlapiLogExecution('debug', 'test', 'addressid: ' + addressid + ' -- linecount: ' + customAddressesLineCount);
for (var i = 1; i <=customAddressesLineCount; i++)
{
var addressinternalid = nlapiGetLineItemValue('iladdrbook','iladdrinternalid',i); // get internal id of custom address book
if (addressinternalid == addressid) // match it with the id of custom address being set
{
var addr = nlapiGetLineItemValue('iladdrbook','iladdrshipaddr1',i);
var customState = nlapiGetLineItemValue('iladdrbook','iladdrshipstate',i); // get your state
nlapiLogExecution('debug', 'test', 'address: ' + addr + ' -- state: ' + customState);
return customState;
}
}
}