I am using the following code to try and pull a custom field value from the selected shipping address on a sales order. I can see that the subrecord is successfully retrieved in the browser debugger, but I cannot figure out why it is returning an undefined value for custrecord_osi_route_code. custrecord_osi_route_code is a custom dropdown list on the address record and there is definitely a value in the addresses I am selecting. Even if I change the script to pick a default field like zip, it still returns an undefined value. Any help is appreciated!
** * @NApiVersion 2.x
* @NScriptType ClientScript
*/
define(['N/currentRecord'],
function(currentRecord) {
function SetOSIRouteCode(context){
try{
var rec = context.currentRecord;
if(context.fieldId == 'shipaddress'){
var addrSubrec = rec.getSubrecord({
fieldId: 'shippingaddress'
});
var OSIRouteCode = addrSubrec.getValue({
fieldid: 'custrecord_osi_route_code'
});
rec.setValue({
fieldid: 'custbody_osi_route_code',
value: OSIRouteCode
});
}
} catch(e) {
console.log("Error setting OSI Route Code");
console.error(e);
}
}
return {
fieldChanged: SetOSIRouteCode
};
});