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:
-
Load the record.
-
Get the subrecord using the
getSubrecord()method. Pass anoptionsobject with afieldIdthat 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
locRecordis a loaded location record, you can use the following expression to retrieve its main address subrecord:... const subrec = locRecord.getSubrecord({ fieldId: 'mainaddress' }); ... -
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' }); ... -
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 }); ...