Using SuiteScript 2.x to Update a Body Field Subrecord
If the business logic of the parent record permits it, your script can load an existing body field subrecord and make changes to it.
To edit a subrecord, your script must use the N/record Module. The script can use either dynamic or standard mode.
To learn about SuiteScript scripting modes, see SuiteScript 2.x Standard and Dynamic Modes
To update a body field subrecord:
-
Load the record.
-
Retrieve the subrecord with the Record.getSubrecord(options) 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 the inventory detail subrecord associated with an assembly build record:
... var subrec = call.getSubrecord({ fieldId: 'inventorydetail' }); ...
-
Update body fields on the subrecord using the Record.setValue(options) method. Be aware that not all subrecords have writable body fields.
-
If the subrecord has a sublist whose values 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 with 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. This field takes four arguments:
-
A sublistId.
-
A fieldId, which identifies the field on the sublist that contains the subrecord.
-
A line number, which identifies the sublist line that contains the subrecord you want to change.
-
The new 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 Editing a Body Field Address Subrecord Example and Editing a Body Field Inventory Detail Subrecord Example.