Use the N/currentRecord module to access the record that is active in the current client context. This module is always a dynamic object and mode of work is always dynamic, not deferred dynamic/standard. For more information, see SuiteScript 2.x Standard and Dynamic Modes. Be aware that when the current record is in view mode it cannot be edited; it is a read-only record when in view mode. As such, any set APIs do not work on the current record in view mode.
You can use the currentRecord module in the following types of scripts:
- Entry point client scripts — These scripts use the
@NScriptType ClientScriptannotation. (For details, see SuiteScript 2.x JSDoc Validation.) The system automatically provides this type of script with a currentRecord.CurrentRecord object that represents the current record. For this reason, an entry point client script does not have to explicitly load the N/currentRecord module. To access the currentRecord object, create a variable and initialize it to the value of thescriptContext.currentRecordproperty, which is available in each of the SuiteScript 2.x Client Script Entry Points and API. For an example, see SuiteScript Client Script Sample. - Client custom modules — These scripts do not use an
@NScriptTypeannotation (see SuiteScript 2.x Custom Modules). For these scripts, you must manually load the N/currentRecord module by naming it in the script’s define statement. Additionally, you must actively retrieve a currentRecord.CurrentRecord object by using the currentRecord.get() or currentRecord.get.promise() method. For an example, see N/currentRecord Module Script Samples.
Like the N/record Module, the currentRecord module provides access to body and sublist fields. However, you should use the record module for server scripts and for cases where a client script needs to interact with a record other than the currently active record. You should use the currentRecord module for client scripts that need to interact with the currently active record.
Additionally, the functionality of the two modules varies slightly. For example, the currentRecord module does not permit the editing of subrecords, although subrecords can be retrieved in view mode. For additional details, see the following topics: