Updating a Body Field Subrecord in SuiteScript 2.1
You can edit an existing body field subrecord if the parent record's business logic allows it.
To edit a subrecord, your script must use the N/record 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 update a body field subrecord:
-
Load the record.
-
Retrieve the subrecord with the Record.getSubrecord(options) method. Pass an
optionsobject 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 example, if
callis a loaded assembly build record, you can use the following expression to retrieve its inventory detail subrecord:... const subrec = call.getSubrecord({ fieldId: 'inventorydetail' }); ... -
Use the Record.setValue(options) method to update the subrecord's body fields. Be aware that not all subrecords have writable body fields.
-
If the subrecord has a sublist you want to change, you can:
-
If your script uses dynamic mode, use the following steps for each value you want to change:
-
Identify the line you want to change using the Record.selectLine(options) method.
-
For each value you want to change, use the Record.setCurrentSublistValue(options) method to identify the field and the new value.
-
Save your changes to the subrecord's sublist line with the Record.commitLine(options) method.
-
-
If your script uses standard mode, use the Record.setSublistValue(options) method to update each field that you want to change. Pass an
optionsobject with the following properties:-
sublistId, which identifies the subrecord's sublist. -
fieldId, which identifies the field on the subrecord's sublist that you want to change. -
line, which identifies the line on the subrecord's sublist that you want to change. -
value, the new field value.
-
-
-
Save the record with the Record.save(options) method.
For full script example showing how to edit a body field subrecord using dynamic mode, see Updating a Body Field Address Subrecord Example and Updating a Body Field Inventory Detail Subrecord Example.