Retrieving an Address Sublist Subrecord Example

This example loads an employee record and selects a line on the address sublist. It retrieves a value from the sublist line that's not part of the subrecord. It also retrieves the address subrecord and reads one of its fields. The script logs both values.

This example uses standard mode, but you can also use dynamic 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.EMPLOYEE,
                id: 1863,
                isDynamic: false
           });

        // Retrive a value from the sublist line
        const labelValue = rec.getSublistValue({
            sublistId: 'addressbook',
            fieldId: 'label',
            line: 0
        });

        // Retrieve the subrecord associated with that same line.
        const subrec = rec.getSublistSubrecord({
            sublistId: 'addressbook',
            fieldId: 'addressbookaddress',
            line: 0
        });

        // Create a variable to initialize it to the
        // value of the subrecord's city field.
        const cityValue = subrec.getValue({
            fieldId: 'city'
        });

        // Print the retrieved values to the execution log.
        try {
            log.debug({
                title: 'label value',
                details: 'label value: ' + labelValue
            });
             
            log.debug({
                title: 'city value',
                details: 'city value: ' + cityValue
            });
        } catch (e) {
            log.error({
                title: e.name,
                details: e.message
            });
        }
    };
    return { afterSubmit };
}); 

        

Related Topics

General Notices