Retrieving a Body Field Subrecord in SuiteScript 2.1

You might need to retrieve data from a subrecord in a body field.

To retrieve a subrecord, your script can use either the N/record Module or the N/currentRecord Module. You can use either dynamic or standard mode.

To learn about SuiteScript scripting modes, see SuiteScript 2.1 Standard and Dynamic Record Modes

To use SuiteScript 2.1 to retrieve a body field subrecord:

  1. Load the record.

  2. Get the subrecord using the getSubrecord() method. Pass an options object with a fieldId that identifies the body field containing the subrecord. In the Records Browser, the field that holds the subrecord is identified as a field of type summary. For more information, see Record.getSubrecord(options).

    For example, if locRecord is a loaded location record, you can use the following expression to retrieve its main address subrecord:

                    ...
    const subrec = locRecord.getSubrecord({
         fieldId: 'mainaddress'
    });
    ... 
    
                  
  3. To retrieve a value from the subrecord's body, use the getValue() method. For more information, see Record.getValue(options). For example, use the following expression to retrieve a value from an address subrecord's body:

                    ...
    const cityValue = subrec.getValue({
        fieldId: 'city'
    });
    ... 
    
                  
  4. To retrieve a value from the subrecord's sublist, use the getSublistValue() method. For more information, see Record.getSublistValue(options). For example, use the following expression to retrieve a value from an inventory detail subrecord's sublist:

                    ...
    const inventoryNumber = subrec.getSublistValue({
        sublistId: 'inventoryassignment',
        fieldId: 'receiptinventorynumber',
        line: 4
    });
    ... 
    
                  

Related Topics

General Notices