0
votes

I have a quirky issue with NetSuite. On a Sales Order which has 'Enable Line Item Shipping' checked, meaning Multiple Shipping Routes are Enabled, the shipping address goes on the item line level.

via SuiteScript, I can access the address on the line level IF it is selected from the address book.

However, when that address is a custom address that is entered on the fly, I have no idea how to get to those fields in a beforeSubmit function.

Any pointers would be much appreciated!

2

2 Answers

0
votes

You can get the selected address details using either or below two

nlapiGetLineItemValue('item','shipaddress',1)
nlapiGetLineItemText('item','shipaddress',1)

The above would only give you the id, or label of address record. But, would be hard to access the address details on the client side.

However, using sub record APIs you can access the record on server-side in user event script using sub record APIs:

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);
0
votes

Figured it out! For those lost souls who venture here in the future:

Below is a function you can use on a sales order line level to loop through the custom addresses and pull out specific information.

Hopefully, this will be added to the NetSuite documentation at some point.

Note that I was doing this specifically for the state information. If you want to see what other fields are available, add &xml=T to the end of a submitted sales order URL and search for iladdrbook in the resuling xml structure. It is actually treated like a line item.

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;
     }
    }
}