Subrecord Scripting in SuiteScript 2.x Compared With 1.0

Compared with SuiteScript 1.0, SuiteScript 2.x introduces the following changes in how you script subrecords:

A Single Method Lets You Create and Load Subrecords

In SuiteScript 1.0, you use one set of APIs to create subrecords and another set to edit subrecords. For example, you could use nlapiCreateSubrecord to create a subrecord and you could use nlapiEditSubrecord to edit a subrecord.

By contrast, in SuiteScript 2.x, any method that creates a subrecord can also be used to load that subrecord for editing. These methods all have the word get in their names. For example, you use the getSubrecord() method to create or load a subrecord that exists on the body of a record. You use the getSublistSubrecord() or getCurrentSublistSubrecord() method to create or load a subrecord that exists on a sublist line.

When you use any of these methods, the system responds with the following logic:

Subrecords Do Not Have to Be Explicitly Saved

In SuiteScript 1.0, you had to explicitly save a subrecord prior to saving the record. However, in SuiteScript 2.x, after you create a subrecord or make changes to one, you are not required to explicitly save the subrecord (and no methods exist for that purpose). Your new subrecord is saved at the time you save the record. The same rule applies if you make changes to an existing subrecord. Your updates are saved at the time you save the record.

To Create Addresses, You Must Use Subrecord Methods

The address subrecord was introduced in version 2014.2. Prior to that time, each address was represented on a record as a series of body fields or as a line in a sublist.

After the introduction of the address subrecord, SuiteScript 1.0 was enhanced to support two methods of interacting with addresses:

However, in SuiteScript 2.x, to create an address, you must use subrecord methods. The system does not provide logic for the legacy address body and sublist fields. For that reason, to create, edit, or load an address in SuiteScript 2.x, you must instantiate the address subrecord by referencing the appropriate summary field.

Related Topics

SuiteScript 2.x Scripting Subrecords
About Subrecords
Scripting Subrecords that Occur on Sublist Lines
Scripting Subrecords that Occur in Body Fields

General Notices