NetSuite - Custom Fields - Assigned to Addressbook but cant access using JS

Viewed 330

I am currently writing a script on the Sales Order to pull fetch a custom field attached to the selected shipping address. I am able to pull all of the address fields (city,zip, etc) but I am unable to figure out how to access any of the attached custom fields to the address.

Example script:

var custid = document.getElementById("hddn_entity_fs").value;
var shiptoid = document.getElementById("hddn_shipaddresslist2").value;

var customer = nlapiLoadRecord("customer", custid);
var itemCount = customer.getLineItemCount('addressbook');

for (var i = 1; i < itemCount; i++) {
  if (customer.getLineItemValue('addressbook', 'id', i) == shiptoid) {

    //this works
    var zip = customer.getLineItemValue('addressbook', 'zip', i);
    console.log('zip:' + zip);

    //this does not work
    var custrecord19 = customer.getLineItemValue('addressbook', 'custrecord19', i);
    console.log('custrecord19:' + custrecord19);
  }
}

I am sure I am missing something simple. Any help greatly appreciated!

Zip

1 Answers

Custom fields on address are actually on the address record

so something like:

SS1.0 dynamic mode. Apparently server side only.

var customer = nlapiLoadRecord('customer', custid, {recordmode:'dynamic'});
...
customer.selectLineItem('addressbook', i);
var addr = customer.editCurrentLineItemSubrecord('addressbook', 'addressbookaddress');
console.log(addr.getFieldValue('custrecord19'));

or SS1 server side not dynamic

var addr = custRec.viewLineItemSubrecord('addressbook', 'addressbookaddress', i);
console.log(addr.getFieldValue('custrecord19'));

SS2.0 works client or server side

var addr = custRec.getSublistSubrecord({sublistId:'addressbook', fieldId:'addressbookaddress', line:i});
console.log(addr.getValue({fieldId:'custrecord19'}));

It's quite doable for an account to have a mix of SS1 and SS2 scripts.

In terms of getting this to work I'd suggest changing your current client script to SS2.

below is a skeleton client script:

/**
 * @NApiVersion 2.x 
 * @NScriptType ClientScript
 */
define(['N/currentRecord', 'N/ui/message', 'N/url', 'N/https', 'N/search'],
    function(rec, msg, url, http, search) {



        return {
            fieldChanged : function(){ console.log('fired field changed');},
            postSourcing: function(){ console.log('fired sourcing');}
        };
    });
Related