Retrieving an Order Schedule Subrecord Example

The following example loads a blanket purchase order record. It selects a line on the item sublist, then retrieves the order schedule associated with that line. It reads two values from the subrecord and prints them to the script deployment execution log.

If you want to use this script, you must meet the following prerequisites:

This example uses dynamic mode, but you could also load the subrecord using standard mode. 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
    };
}); 

        

Related Topics

Using SuiteScript 2.x to Retrieve a Sublist Subrecord
Retrieving an Address Subrecord Example

General Notices