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:

This example uses dynamic mode, but you can also use standard mode to update the subrecord. For general details about using either approach to update a sublist subrecord, see Updating 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 blanket purchase order record.
        const 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.
        const 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.
        const 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 {
            const recId = rec.save();
            log.debug({
                title: 'Record updated successfully',
                details: 'Id: ' + recId
            });
        } catch (e) {
            log.error({
                title: e.name,
                details: e.message
            });
        }
    };
    return { afterSubmit };
}); 

        

Related Topics

General Notices