SuiteScript 2.x Standard and Dynamic Modes
When you create, copy, load, or transform records in SuiteScript, you can work with records in standard or dynamic mode.
Standard mode:
When a SuiteScript 2.x script creates, copies, loads, or transforms a record in standard mode, the record’s body fields and sublist line items are not sourced, calculated, and validated until the record is saved with Record.save(options). You might also see this referred to as "deferred dynamic mode" in the SuiteScript help.
When you work with a record in standard mode, in most cases, you don't need to set values in any particular order. When you submit the record, NetSuite will process the fields and sublist items in the right order, no matter how your script is organized. See Getting Text in SuiteScript 2.x Record Modes.
Dynamic mode:
When a SuiteScript 2.x script creates, copies, loads, or transforms a record in dynamic mode, the record’s body fields and sublist line items are sourced, calculated, and validated in real time. Dynamic mode makes the record behave like it would in the NetSuite UI.
In dynamic mode, the Legacy Tax field Tax Code isn't automatically transferred when a requisition becomes a purchase order. For more information, see Tax Code Limitations When Using SuiteScript 2.x.
In dynamic mode, the order of setting field values is important. This might feel limiting to some developers. You'll probably need to check the UI often when scripting in dynamic mode. For instance, when creating an invoice in the UI, you wouldn't set the Terms field before the Customer field. That's because setting the Customer field will override the Terms field value. On an invoice, the value of Terms is sourced from the terms specified on the Customer record. This behavior also applies to dynamic scripting. If you don't set field values in the right order in your script, some values might get overridden.
How you can tell if a record is in dynamic mode:
You can determine if a record is in dynamic mode using these two SuiteScript 2.x properties:
-
Record.isDynamic (for server scripts)
-
CurrentRecord.isDynamic (for client scripts)
Record Modes and User Event Scripts
User event scripts that use newRecord or oldRecord objects always run in standard mode. FThis is why you might see the SSS_INVALID_API_USAGE error in these situations:
-
When the user event script executes on a record that is being created, and the script attempts to use Record.getText(options) without first using Record.setText(options) for the same field.
-
When the user event script executes on an existing record or on a record being created through copying, and the script uses Record.setValue(options) on a field before using Record.getText(options) for the same field.
Getting Text in SuiteScript 2.x 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).
Record Module Method Considerations
Be aware that the record.create(options), record.copy(options), record.load(options), and record.transform(options) methods work in standard mode by default. To use these methods in dynamic mode, set the .isDynamic
property for each one.