Dynamically Modify the NetSuite Address Block Shown

Sample script that would dynamically hide the default Bill-to address and then dynamically show the Ship-to address in Customer Record

SuiteScript 2.0 to Dynamically Show Address Block

The following 2.0 code snippet would be added to the BeforeLoad UserEvent.

//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: context.newRecord.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});
    }
}

Leave a comment

Your email address will not be published. Required fields are marked *