N/currentRecord Module Members for SuiteScript Development

The N/currentRecord module in SuiteScript provides methods and properties for accessing and manipulating the current record in client scripts.

·3 min read·View Oracle Docs

TL;DR Opening

The N/currentRecord module is essential for SuiteScript developers, enabling access to the currently active record within client scripts. This module provides a dynamic way to manipulate record data in real-time, enhancing user experience.

Overview of N/currentRecord Module

The N/currentRecord module allows developers to access the active record in the current client context. This module operates in dynamic mode, meaning that any changes made to the record are reflected in real-time within the NetSuite user interface. However, it is important to note that when a record is in view mode, it becomes read-only, and any attempt to edit it using set APIs will fail.

Script Types Supporting N/currentRecord

You can use the N/currentRecord module in various script types:

  • Entry Point Client Scripts: These scripts automatically have access to the currentRecord object via the scriptContext.currentRecord property. Developers do not need to explicitly load the N/currentRecord module.
  • Client Custom Modules: For scripts lacking an @NScriptType annotation, the N/currentRecord module must be manually loaded in the define statement, and the currentRecord object must be explicitly retrieved using currentRecord.get() or currentRecord.get.promise().

Accessing Record Fields

Similar to the N/record module, the N/currentRecord module grants access to body and sublist fields. However, the N/currentRecord module is specifically designed for client scripts that need to manipulate the currently active record, while the N/record module is used for server scripts and when dealing with non-active records.

Member Types in N/currentRecord

The following table summarizes the members of the N/currentRecord module:

Member NameTypeReturn TypeSupported Script TypesDescription
currentRecord.ColumnObject-Client scriptsRepresents a column in a sublist on the current record.
currentRecord.CurrentRecordObject-Client scriptsRepresents the record active on the current page.
currentRecord.FieldObject-Client scriptsRepresents a body or sublist field.
currentRecord.SublistObject-Client scriptsRepresents a sublist on the current record.
currentRecord.get()MethodcurrentRecord.CurrentRecordClient scriptsRetrieves a record object representing the current record.
currentRecord.get.promise()MethodPromiseClient scriptsRetrieves a promise for an object representing the current record.

Field Object Members

The Field object within the currentRecord module contains specific methods:

Member NameTypeReturn TypeSupported Script TypesDescription
Field.getSelectOptions(options)MethodarrayClient scriptsReturns an array of available options for select fields.
Field.insertSelectOption(options)MethodvoidClient scriptsInserts an option into certain types of select fields.
Field.removeSelectOption(options)MethodvoidClient scriptsRemoves an option from certain types of select fields.
Field.idPropertystringClient scriptsReturns the internal ID of the field.
Field.isDisabledPropertybooleanClient scriptsIndicates if the field is disabled on the record form.
Field.labelPropertystringClient scriptsReturns the UI label for the field.

Best Practices

  • Always ensure the current record is not in view mode when attempting to modify field values.
  • Utilize the currentRecord module's methods to interact efficiently with active records and sublists in your client scripts.
  • When working with select fields, remember that you can only manipulate options on fields that were initialized from Suitelets or beforeLoad scripts.

Who This Affects

  • Developers: Those creating client scripts in SuiteScript will directly benefit from using the N/currentRecord module.

Key Takeaways

  • The N/currentRecord module is crucial for dynamic record manipulation in client scripts.
  • It offers unique methods and properties for accessing the active record's fields and sublists.
  • Understanding working modes (dynamic vs. view) is essential to effectively utilize this module.

Frequently Asked Questions (4)

How can I access the N/currentRecord module in a client custom module?
For client custom modules without an @NScriptType annotation, you must manually load the N/currentRecord module in the define statement and retrieve the currentRecord object using currentRecord.get() or currentRecord.get.promise().
Can the N/currentRecord module be used in server-side scripts?
No, the N/currentRecord module is designed specifically for use in client scripts to manipulate the currently active record. For server-side scripts or non-active records, you should use the N/record module.
What happens if I try to edit a record in view mode using the N/currentRecord module?
When a record is in view mode, it becomes read-only. Any attempts to edit it using set APIs from the N/currentRecord module will fail.
Which method would I use to retrieve a promise for the current record in a client script?
You would use the currentRecord.get.promise() method to retrieve a promise for the current record in a client script.
Source: Field Object 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 →