Using SuiteScript 2.x to Retrieve a Body Field Subrecord
In some cases, you may want to retrieve data from a subrecord that occurs in a body field.
To retrieve a subrecord, your script can use either the N/record Module or the N/currentRecord Module. Your script can use either dynamic or standard mode.
To learn about SuiteScript scripting modes, see SuiteScript 2.x Standard and Dynamic Modes
To use SuiteScript 2.x to retrieve a body field subrecord:
-
Load the record.
-
Retrieve the subrecord with the getSubrecord() method. This method takes one argument: 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, you could use an expression like the following to load an address subrecord stored in the body field of a location record:
... var subrec = call.getSubrecord({ fieldId: 'mainaddress' }); ...
-
If you want to retrieve a value from the body of the subrecord, use the getValue() method. For example, you could use an expression like the following to retrieve a detail from the body of an address subrecord:
... var cityValue = subrec.getValue({ fieldId: 'city' }); ...
-
If you want to retrieve a value from the subrecord’s sublist, use the getSublistValue() method. For example, you could use an expression like the following to retrieve a detail from the sublist of an inventory detail subrecord:
... var cityValue = subrec.getValue({ sublistId: 'inventoryassignment', fieldId: 'receiptinventorynumber', line: 4, }); ...