Using SuiteScript 2.x to Update a Body Field Subrecord

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.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. The method requires 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. Use the Record.setValue(options) method update the subrecord's body fields. Be aware that not all subrecords have writable body fields.

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

      1. Identify the line you want to change using 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

General Notices