Updating an Order Schedule Sublist Subrecord Example
The following example loads an existing blanket purchase order record. It selects a line on the record’s item sublist, retrieves the subrecord associated with that line, and makes changes to the subrecord.
To use this example, you must meet the following prerequisites:
-
The Blanket Purchase Order feature must be enabled at Setup > Company > Enable Features , on the Transactions subtab.
-
The blanket purchase order record that you reference should have at least one line in the item sublist. The line should reference an existing order schedule subrecord.
This example uses dynamic mode, but you could also update the subrecord using standard mode. For general details about using either approach to update a sublist subrecord, see Using SuiteScript 2.x to Edit a Subrecord that Occurs in a Sublist Field. To learn about SuiteScript scripting modes, see SuiteScript 2.x Standard and Dynamic Modes
define([ 'N/record' ],function(record) {
function afterSubmit(context) {
// Load the blanket purchase order record.
var rec = record.load({
type: record.Type.BLANKET_PURCHASE_ORDER,
id: 3319,
isDynamic: true
});
// Select the sublist and line.
rec.selectLine({
sublistId: 'item',
line: 0
});
// Retrieve the subrecord.
var subrec = rec.getCurrentSublistSubrecord({
sublistId: 'item',
fieldId: 'orderschedule'
});
// Select the appropriate line in the subrecord's sublist.
subrec.selectLine({
sublistId: 'schedule',
line: 0
});
// Identify the field to be modified, and set new value.
var nextQuarter = new Date();
nextQuarter.setDate(nextQuarter.getDate() + 90);
subrec.setCurrentSublistValue({
sublistId: 'schedule',
fieldId: 'trandate',
value: nextQuarter
});
// Save the subrecord's sublist line.
subrec.commitLine({
sublistId: 'schedule'
});
// Save the item sublist line that contains the subrecord.
rec.commitLine({
sublistId: 'item'
});
// 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
};
});