Retrieving an Order Schedule Sublist Subrecord Example
The following example loads a blanket purchase order record. It selects a line on the item sublist and retrieves the associated order schedule. It reads two values from the subrecord and logs them.
To use this script, make sure you meet these requirements:
-
The Blanket Purchase Order feature must be enabled at Setup > Company > Enable Features , on the Transactions subtab.
-
The blanket purchase order record you reference must have at least one line in the Item sublist, and that line should include an order schedule subrecord.
This example uses dynamic mode, but you can also use standard mode to load the subrecord. For general details about using either approach to retrieve a sublist subrecord, see Retrieving a Sublist Subrecord in SuiteScript 2.1.
To learn about SuiteScript scripting modes, see SuiteScript 2.1 Standard and Dynamic Record Modes
/**
* @NApiVersion 2.1
* @NScriptType usereventscript
*/
define([ 'N/record' ], (record) => {
const afterSubmit = (context) => {
// Load the record.
const rec = record.load({
type: record.Type.BLANKET_PURCHASE_ORDER,
id: 3120,
isDynamic: true
});
// Retrieve the subrecord.
rec.selectLine({
sublistId: 'item',
line: 0
});
const subrec = rec.getCurrentSublistSubrecord({
sublistId: 'item',
fieldId: 'orderschedule',
});
// Create a variable and initialize it to the
// value of the trandate field.
const dateValue = subrec.getSublistValue({
sublistId: 'schedule',
fieldId: 'trandate',
line: 0
});
// Create a variable and initialize it to the
// value of the memo field.
const memoValue = subrec.getSublistValue({
sublistId: 'schedule',
fieldId: 'memo',
line: 0
});
// Print the retrieved values to the execution log.
try {
log.debug({
title: 'date value',
details: 'date value: ' + dateValue
});
log.debug({
title: 'memo value',
details: 'memo value: ' + memoValue
});
} catch (e) {
log.error({
title: e.name,
details: e.message
});
}
};
return { afterSubmit };
});