Scenario:
User wants to set the values of Shipping Address subrecord using Client Script for existing records.
Solution:
/**
*
* @NApiVersion 2.x
* @NScriptType ClientScript
*
*/
define([‘N/record’, ‘N/currentRecord’, ‘N/runtime’],
function pageInit(scriptContext) {
try {
var recordid = scriptContext.currentRecord.id;
var recordtype = scriptContext.currentRecord.type;
var rec = record.load({
type: recordtype,
id: recordid,
isDynamic: true
});
var subrec = rec.getSubrecord({
fieldId: ‘shippingaddress’
});
subrec.setValue({
fieldId: ‘country’,
value: ‘US’
});
} catch (err) {
alert(err);
}
return {
pageInit: pageInit
}
});