Using SuiteScript 2.x to Retrieve a Shipping Address Example

This user event script retrieves all fields from a transaction's shipping address.

Deploy this script on a sales order or another transaction with a shippingaddress summary field. After creating a new transaction with a shipping address, the address will be logged in the script deployment record's execution log.

          /**
*@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

General Notices