Using SuiteScript 2.x to Retrieve one Value from a Shipping Address Example
The following script loads a sales order record. It retrieves a value from the shipping address and prints it to the execution log.
Note:
For details about working with a transaction’s shipping or billing address, see Scripting Transaction Shipping and Billing Addresses.
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define([ 'N/record' ],function(record){
function pageInit(){
// Load the record.
var rec = record.load({
type: record.Type.SALES_ORDER,
id: 5025,
isDynamic: true
});
// Retrieve the subrecord.
var subrec = rec.getSubrecord({
fieldId: 'shippingaddress'
});
// Create a variable and initialize it to the
// value of the subrecord's city field.
var cityValue = subrec.getValue({
fieldId: 'city'
});
// Print the value to the execution log.
try {
log.debug({
title: 'city value',
details: 'city value: ' + cityValue
});
} catch (e) {
log.error({
title: e.name,
details: e.message
});
}
}
return {
pageInit: pageInit
}
});