How To Dynamically Draw a NetSuite Address

This article is relevant if you want to display a different NetSuite address block on a form instead of the default provided.


A client recently came to us asking a question: “In the out of the box Customer Form, the Address that is seen is the Default Billing Address. We have the need to show the Default Shipping Address rather than the Billing Address. How can I accomplish that?”

The address shown on the header customer form is read-only. NetSuite addresses are stored as a list hanging from the entity object. Only one address in the list can be marked as a default Bill-to and a default Ship-to address. This default information is used to help drive transaction sourcing defaults.
Since our client is technically oriented, they wanted a sample script to help them solve their own challenge.

Dynamically Modify the NetSuite Address Block Shown

As a response, I asked one of our senior consultants to create a sample script that would dynamically hide the default Bill-to address and then dynamically show the Ship-to address. Thus, the following code pattern gets the job done.

SuiteScript 2.0 to Dynamically Show Address Block

The following 2.0 code snippet would be added to the BeforeLoad UserEvent. The assumption is that you have some basic SuiteScript 2.0 knowledge to set up the function handling:

//detect that we are in view or edit mode
if (context.type != context.UserEventType.CREATE && runtime.executionContext == runtime.ContextType.USER_INTERFACE) {                  
    //get the value of the ship-to address block by leveraging NetSuite's default ship to information on customer record header
    var shipAddress = search.lookupFields({type: context.newRecord.type, id:, columns: ["shipaddress"]});
    //create the field and add it to the form; push the data in an format it to make it feel right
    var fld = context.form.addField({id: "custpage_default_shipping", label: "Shipping Address", type: serverWidget.FieldType.TEXT});
    if (context.type == context.UserEventType.VIEW){
        fld.defaultValue = shipAddress.shipaddress.replace(/\n/g,"<br>");
    } else {
        fld.defaultValue = shipAddress.shipaddress;
        fld.updateDisplayType({displayType: serverWidget.FieldDisplayType.DISABLED});
    context.form.insertField({field: fld, nextfield: "defaultaddress"});
    //hide NetSuite's default address field on the form
    var fld = context.form.getField("defaultaddress");
    if (fld){
        fld.updateDisplayType({displayType: serverWidget.FieldDisplayType.HIDDEN});

Work with Great NetSuite Professionals

What’s great about the NetSuite platform is our ability to enhance the user experience and take matters into our own hands — when we want to. In this example, I am fortunate I get to work with a team of professionals that share my passion for making our clients’ NetSuite investment produce greater results. Perhaps you too share that passion and you want to be surrounded by a team that values you for your creativity, ingenuity, leadership, and desire for autonomy. If so, let’s have a conversation.

Be Sociable, Share!

Marty Zigman

Holding all three official certifications, Marty is Southern California's NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 25 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

More Posts - Website - Twitter - Facebook - LinkedIn - Google Plus - YouTube

| Category: NetSuite, Technical | Leave a comment

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>