Updating a Body Field Address Subrecord Example
The following example loads a subsidiary record. It also loads and edits the address subrecord in the mainaddress field.
You need a OneWorld account to use this script.
For general details on updating body field subrecords, see Updating a Body Field Subrecord in SuiteScript 2.1.
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define([ 'N/record' ], (record) => {
const afterSubmit = (context) => {
// Load the record.
const rec = record.load({
type: record.Type.SUBSIDIARY,
id: 1,
isDynamic: true
});
// Load the subrecord.
const subrec = rec.getSubrecord({
fieldId: 'mainaddress'
});
// Make changes to one field.
subrec.setValue({
fieldId: 'addr1',
value: '12331-A Riata Trace Parkway'
});
// Save the record.
try {
const recId = rec.save();
log.debug({
title: 'Record updated successfully',
details: 'Id: ' + recId
});
} catch (e) {
log.error({
title: e.name,
details: e.message
});
}
};
return { afterSubmit };
});