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:
-
If a subrecord instance already exists in the specified field, the subrecord is loaded.
-
If no subrecord instance exists, the system creates one. You can then set values on the field. The subrecord is saved when you save the record.
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
Before the address subrecord was introduced, 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:
-
You can interact with addresses using subrecord APIs (which is the preferred method)
-
You can interact with addresses using the legacy approach of setting values for the address body and sublist fields that used to exist. This support was made possible by logic added to the system that read the values set in this manner and created an address subrecord on behalf of the 1.0 script. Because this support exists in 1.0, these deprecated fields are displayed in the SuiteScript Records Browser as available fields.
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.