Retrieving an Order Schedule 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 Using SuiteScript 2.x to Retrieve a Sublist Subrecord.
To learn about SuiteScript scripting modes, see SuiteScript 2.x Standard and Dynamic Modes
/**
* @NApiVersion 2.x
* @NScriptType usereventscript
*/
define([ 'N/record' ],function(record) {
function afterSubmit(context) {
// Load the record.
var rec = record.load({
type: record.Type.BLANKET_PURCHASE_ORDER,
id: 3120,
isDynamic: true
});
// Retrieve the subrecord.
rec.selectLine({
sublistId: 'item',
line: 0
});
var subrec = rec.getCurrentSublistSubrecord({
sublistId: 'item',
fieldId: 'orderschedule',
});
// Create a variable and initialize it to the
// value of the trandate field.
var dateValue = subrec.getSublistValue({
sublistId: 'schedule',
fieldId: 'trandate',
line: 0
});
// Create a variable and initialize it to the
// value of the memo field.
var 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: afterSubmit
};
});