ANS-0883 · SUITESCRIPT DEVELOPMENT

How to Retrieve Custom Address Field Values from NetSuite Transactions

This guide details two scripting methods for retrieving custom address field values from NetSuite transaction records.

Short answer

Custom address field values on NetSuite transactions can be retrieved via scripting. Methods include loading the associated customer record, then iterating its address book subrecord to match the address ID and extract the custom field. Alternatively, a NetSuite search can be created to join the transaction with the billing address, directly extracting the custom field value.

Scenario

Users often need to programmatically access custom address field values that are associated with transaction records, such as sales orders. These fields are typically defined on the address subrecord and linked to the transaction's billing or shipping address. The challenge lies in efficiently extracting these specific custom values for further processing or display.

Solution

To retrieve the value of a custom address field from a NetSuite transaction, two primary scripting methods can be employed. It is important to note that the following examples utilize SuiteScript 1.0 APIs, which are deprecated. For new development, NetSuite recommends using SuiteScript 2.x.

  1. Retrieve the custom field value by loading the subrecord within the customer record:

    This method involves loading the transaction record, identifying the associated customer and address ID, and then iterating through the customer's address book sublist to locate the specific address and extract the custom field value from its subrecord.

javascript
    var transactionRecord  nlapiLoadRecord('salesorder', 554395);
    // This should work also when using shipaddresslist
    var addressRecordId  transactionRecord .getFieldValue('billaddresslist');
    var customerRecord  nlapiLoadRecord('customer',
    transactionRecord.getFieldValue('entity'));
    var customFieldValue  null;
    for (var i  1; i < customerRecord.getLineItemCount('addressbook'); i++)
    {
        customerRecord.selectLineItem('addressbook', i);
        var id  customerRecord.getCurrentLineItemValue('addressbook', 'id');
        if (id  addressRecordId)
        {
            var subrecord
    customerRecord.viewCurrentLineItemSubrecord('addressbook',
    'addressbookaddress');
            customFieldValue  subrecord.getFieldValue('custrecord_contact_id');
        }
    }
  1. Create a search to get the value of your custom field:

    This approach leverages NetSuite's search capabilities to directly query for the transaction and join to its billing address, allowing for the extraction of the custom field value in a more streamlined manner.

javascript
    var filters  [];
    filters.push(new nlobjSearchFilter('internalid', null, 'anyof', 554395));
    filters.push(new nlobjSearchFilter('mainline', null, 'is', 'T'));
    var searchResults  nlapiSearchRecord('salesorder', null, filters, new
    nlobjSearchColumn('custrecord_contact_id', 'billingaddress'));
    var customFieldValue
    searchResults[0].getValue('custrecord_contact_id', 'billingaddress');

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant