SuiteScript 2.1 Standard and Dynamic Record Modes
When you create, copy, load, or transform records in SuiteScript, you can work with records in standard or dynamic mode.
Standard and Dynamic Modes
The following table shows how records behave in standard and dynamic modes:
|
Behavior |
Standard Mode |
Dynamic Mode |
|---|---|---|
|
Field sourcing, calculation, and validation |
NetSuite processes body fields and sublist line items when you save the record with Record.save(options). |
NetSuite processes body fields and sublist line items in real time. |
|
Order of setting field values |
In most cases, you can set values in any order. NetSuite processes them in the appropriate order when you save. |
The order matters. Setting one field can source or overwrite values in other fields. For example, on an invoice, set Customer before Terms because setting Customer can overwrite Terms. |
|
Relationship to the NetSuite UI |
Field processing is deferred until the record is saved. |
The record behaves like it does in the UI, including field sourcing and dependencies. |
You might also see standard mode referred to as "deferred dynamic mode" in the SuiteScript help.
Check the NetSuite UI to understand field dependencies when scripting in dynamic mode.
Setting and Checking the Record Mode
The record.create(options), record.copy(options), record.load(options), and record.transform(options) methods use standard mode by default. To create, copy, load, or transform a record in dynamic mode, set the isDynamic option to true.
You can determine if a record is in dynamic mode using these two SuiteScript 2.1 properties:
-
Record.isDynamic - for
Recordobjects fromN/recordin client and server scripts. -
CurrentRecord.isDynamic - for the current UI record in client scripts.
Record Modes and User Event Scripts
The context.newRecord and context.oldRecord objects in user event scripts always use standard mode. This is why you might see the SSS_INVALID_API_USAGE error in these situations:
-
When creating a record, the script calls Record.getText(options) without first calling Record.setText(options) for the same field.
-
For an existing or copied record, the script calls Record.setValue(options) before Record.getText(options) for the same field.
Getting Text in Record Modes
In dynamic mode, you can use Record.getText(options) without limitation, but in standard mode, there are some limits. In standard mode, you can use this method only in these situations:
-
You can use Record.getText(options) on any field where the script has already used Record.setText(options).
-
If you are loading or copying a record, you can use Record.getText(options) on any field except those where the script has already changed the value with Record.setValue(options).