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:

  1. Load the record.

  2. 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'
    });
    ... 
    
                  
  3. Update body fields on the subrecord using the Record.setValue(options) method. Be aware that not all subrecords have writable body fields.

  4. 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:

      1. Identify the line you want to change with the Record.selectLine(options) method.

      2. For each value you want to change, use the Record.setCurrentSublistValue(options) method to identify the field and the new value.

      3. 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.

  5. Save the record with the Record.save(options) method.

Note:

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.

Related Topics

Scripting Subrecords that Occur in Body Fields
Using SuiteScript 2.x to Create a Body Field Subrecord
Using SuiteScript 2.x to Retrieve a Body Field Subrecord
Scripting Transaction Shipping and Billing Addresses

General Notices