Using SuiteScript 2.x to Retrieve a Shipping Address Example

The following user event script gets all fields from the shipping address of a new transaction record.

To use this script, deploy it on a sales order or another transaction that has a shippingaddress summary field. After you create a new transaction that includes a shipping address, the address should be written to the execution log of your script deployment record.

          /**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/

define(['N/record'],function(record){
    function beforeSubmit(context){
        if(context.type==context.UserEventType.CREATE){
            var salesOrder = context.newRecord;
            var shipToAddress = salesOrder.getSubrecord({
                fieldId: 'shippingaddress'
            });
                      
            log.debug({
                title: 'shipping address', 
                details: JSON.stringify(shipToAddress)
            });          
        }
    }
    return {
        beforeSubmit: beforeSubmit
    };
}); 

        

Related Topics

Scripting Transaction Shipping and Billing Addresses
Using SuiteScript 2.x to Create a New Shipping Address Example
Using SuiteScript 2.x to Select an Existing Shipping Address Example
Using SuiteScript 2.x to Retrieve one Value from a Shipping Address Example

General Notices