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