How to access bill city, state, zip, country from billing address of sale order using user event script?
function afterSubmit(context) {
if (context.type !== context.UserEventType.CREATE && context.type !== context.UserEventType.EDIT) {
return;
}
var salesOrder = context.newRecord;
var city = salesOrder.getValue({ fieldId: ‘billcity’ });
var state = salesOrder.getValue({ fieldId: ‘billstate’ });
var zip = salesOrder.getValue({ fieldId: ‘billzip’ });
var country = salesOrder.getValue({ fieldId: ‘billcountry’ });
log.debug(‘Sales Order Address’, ‘City: ‘ + city + ‘, State: ‘ + state + ‘, Zip: ‘ + zip + ‘, Country: ‘ + country);
}
Getting log as:
City:undefined, State:undefined, Zip:undefined, Country:undefined
You need to load the billingaddress
subrecord, then access the fields from there.
var billAddrSubRec = salesOrder.getSubrecord({
fieldId: 'billingaddress'
});
var city = billAddrSubRec.getValue({
fieldId: 'city'
});
And so on. You can find the available fields for the sales order record at https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2023_1/script/record/salesorder.html and the fields for the address subrecord at https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2023_1/script/record/address.html
0