Retrieving 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.1
*@NScriptType UserEventScript
*/
define(['N/record'], (record) => {
const beforeSubmit = (context) => {
if(context.type == context.UserEventType.CREATE){
const salesOrder = context.newRecord;
const shipToAddress = salesOrder.getSubrecord({
fieldId: 'shippingaddress'
});
log.debug({
title: 'shipping address',
details: JSON.stringify(shipToAddress)
});
}
};
return { beforeSubmit };
});