Using SuiteScript 2.x to Retrieve a Sublist Subrecord

In some cases, you may want to retrieve data from a subrecord that occurs in a sublist field.

To retrieve a sublist subrecord, use the N/record Module. Your script can use either dynamic or standard mode. For details, see the following sections:

Retrieving a Sublist Subrecord in Dynamic Mode

If your script uses dynamic mode, you can use the following procedure to retrieve a subrecord that occurs in a sublist field.

To learn about SuiteScript scripting modes, see SuiteScript 2.x Standard and Dynamic Modes

To retrieve a sublist subrecord in dynamic mode:

  1. Load the parent record.

  2. Select the line that contains the subrecord with the Record.selectLine(options).

  3. Retrieve the subrecord with the Record.getCurrentSublistSubrecord(options) method. This method takes two arguments:

    • A sublistId.

    • A fieldId, which identifies the field on the sublist that contains the subrecord. In the Records Browser, the field that holds the subrecord is always identified as a field of type summary.

    For example, suppose you are working with an entity record, such as an employee or customer. You could use an expression like the following to load an address subrecord from the entity’s Address sublist:

                    ...
    var addressSubrecord = rec.getCurrentSublistSubrecord({
        sublistId: 'addressbook',
        fieldId: 'addressbookaddress'
    });
    ... 
    
                  
  4. If you want to retrieve a value from the body of the subrecord, use the Record.getValue(options). For example, you could use an expression like the following to retrieve a detail from the body of an address subrecord:

                    ...
    var cityValue = addressSubrecord.getValue({
        fieldId: 'city'
    });
    ... 
    
                  
  5. If you want to retrieve a value from the subrecord’s sublist, use the Record.getSublistValue(options) method.

Note:

For a full script example showing how to retrieve a sublist subrecord in dynamic mode, see Retrieving an Order Schedule Subrecord Example.

Retrieving a Subrecord in Standard Mode

If your script uses standard mode, use the following procedure to retrieve a sublist subrecord.

To learn about SuiteScript scripting modes, see SuiteScript 2.x Standard and Dynamic Modes

To retrieve a subrecord in standard mode

  1. Load the parent record.

  2. Retrieve the subrecord with the Record.getSublistSubrecord(options) method. This method takes three arguments:

    • A sublistId.

    • A fieldId, which identifies the field on the sublist that contains the subrecord. In the Records Browser, the field that holds the subrecord is always identified as a field of type summary.

    • A line number

    For example, you could use an expression like the following to load an order schedule subrecord from a blanket purchase order record:

                    ...
    var orderScheduleSubrecord = rec.getSublistSubrecord({
        sublistId: 'item',
        fieldId: 'orderschedule',
        line: 0
    });
    ... 
    
                  
  3. If you want to retrieve a value from the body of the subrecord, use the Record.getValue(options) method.

  4. If you want to retrieve a value from the subrecord’s sublist, use the Record.getSublistValue(options) method.

    For example, the order schedule subrecord has a schedule sublist. If you wanted to retrieve the date value from the second line of the schedule sublist, you would use an expression like the following:

                    ...
    var dateValue = orderScheduleSubrecord.getSublistValue({
        sublistId: 'schedule',
        fieldId: 'trandate',
        line: 1
    });
    ... 
    
                  
Note:

For a full script example showing how to retrieve a sublist subrecord in standard mode, see Retrieving an Address Subrecord Example.

Related Topics

Scripting Subrecords that Occur on Sublist Lines
Using SuiteScript 2.x to Create a Subrecord in a Sublist Field
Using SuiteScript 2.x to Edit a Subrecord that Occurs in a Sublist Field

General Notices