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
};
});