N/currentRecord Module: Accessing Active Records in SuiteScript

The N/currentRecord module allows SuiteScript developers to access and manipulate the currently active record in client scripts.

·3 min read·View Oracle Docs

The N/currentRecord module is essential in SuiteScript for accessing the record that is currently active in the client context. It operates in a dynamic manner, meaning it mimics the behavior of the record as displayed in the NetSuite UI. Understanding how this module works is crucial for developers wanting to create effective client-side scripts.

How Does the N/currentRecord Module Work?

The N/currentRecord module is always a dynamic object, ensuring that changes made in scripts reflect immediately within the user interface, as opposed to deferring until the record is saved. Importantly, when a record is in view mode, it becomes read-only, and developers should ensure they do not attempt to edit it using set APIs during this time.

Script Types That Use N/currentRecord

The N/currentRecord module can be utilized in various types of scripts:

  • Entry Point Client Scripts: These scripts are designated with the @NScriptType ClientScript annotation. They are automatically provided with a currentRecord.CurrentRecord object, allowing easy access to the currently active record without requiring a manual load of the N/currentRecord module.
  • Client Custom Modules: Unlike entry point scripts, these may not have an @NScriptType annotation. In this case, developers need to manually load the module while defining it in the script's define statement. Here, retrieving the currentRecord object requires using methods like currentRecord.get() or currentRecord.get.promise().

Usage of N/currentRecord vs. N/record

While both N/currentRecord and N/record modules provide access to body fields and sublist items, they serve slightly different purposes:

  • N/currentRecord: Best suited for client scripts that require interaction with the currently active record.
  • N/record: Recommended for server scripts or when interacting with records other than the currently active one.

Key Functionality and Methods

Understanding the available methods and member objects within the N/currentRecord module is essential:

Member Types:

Member TypeNameDescription
ObjectcurrentRecord.ColumnEncapsulates a column of a sublist.
ObjectcurrentRecord.CurrentRecordRepresents the active record on the current page.
ObjectcurrentRecord.FieldRepresents a body or sublist field.
ObjectcurrentRecord.SublistRepresents a sublist.
MethodcurrentRecord.get()Retrieves the current record object.
MethodcurrentRecord.get.promise()Retrieves a promise for the current record object.

Conclusion

The N/currentRecord module is crucial for any SuiteScript developer working on client scripts that interact with records. Proper understanding and implementation of this module can greatly enhance the functionality and efficiency of client-side scripts.

Source: This article is based on Oracle's official NetSuite documentation.

Key Takeaways

  • The N/currentRecord module facilitates access to the currently active record in client scripts.
  • This module operates dynamically, mirroring UI behaviors.
  • Use it in entry point client scripts without explicit loading; manual loading is required for custom modules.
  • The N/currentRecord is preferred for client interactions, while N/record serves server-side needs.

Frequently Asked Questions (4)

How does the N/currentRecord module handle record changes dynamically?
The N/currentRecord module reflects changes immediately within the NetSuite UI as soon as they are made in client scripts, without waiting for the record to be saved.
Can the N/currentRecord module be used in scripts other than entry point client scripts?
Yes, the N/currentRecord module can also be used in client custom modules, although it requires manual loading in the script's define statement.
What happens if you try to edit a read-only record using the N/currentRecord module?
Attempting to edit a record in view mode, where it is read-only, with set APIs will not work, as the record cannot be modified in this state.
What methods are available for retrieving the current record object with the N/currentRecord module?
You can use the methods currentRecord.get() and currentRecord.get.promise() to retrieve the current record object through the N/currentRecord module.
Source: N/currentRecord Module Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in SuiteScript

View all SuiteScript articles →