N/recordContext Module Members
Explore N/recordContext module members, including methods and their types for SuiteScript development.
The N/recordContext module provides developers with critical functionality to work with record contexts in SuiteScript. This module includes various members that offer insights and methods pertaining to the context within which records are processed.
What are the Members of the N/recordContext Module?
The N/recordContext module consists of the following key members:
| Member Name | Type | Return Type / Value Type | Supported Script Types | Description |
|---|---|---|---|---|
recordContext.RecordContext | Object | Object (read-only) | Client and server scripts | Contains key-value pairs that represent context types and their values. |
recordContext.getContext(options) | Method | recordContext.RecordContext | Client and server scripts | Returns the record context object for a record. |
recordContext.ContextType | Enum | enum (read-only) | Client and server scripts | Holds values for the context type, used in contextTypes for the getContext method. |
Understanding the getContext Method
The recordContext.getContext(options) method is pivotal for accessing the context of records, particularly depending on whether the record is currently loaded in your script.
-
For Unloaded Records: When a record is not yet loaded, the record is specified through the
recordTypeandrecordIdparameters:javascriptrecordContext.getContext({recordType: 'customer',recordId: '123'}); -
For Loaded Records: If the record is already loaded in your script, use the
recordparameter:javascriptrecordContext.getContext({record: customerRecord});
Parameters of the getContext Method
The options parameter is a JavaScript object that consists of several keys:
recordType: string, required if the record is not loaded in your script.recordId: string, required if the record is not loaded in your script.record: record.Record, required if the record is loaded in your script.contextTypes: Array<string>, optional, specifies the types of contexts to retrieve.
Common Errors
The method may throw various errors based on the parameters provided:
MUTUALY_EXCLUSIVE_ARGUMENT: Thrown if both a loaded record and a record ID/record type are provided.MISSING_REQD_ARGUMENT: Triggered when a required parameter is missing.SSS_INVALID_TYPE_ARG: Indicates a wrong parameter type was provided.UNKNOWN_CONTEXT_TYPE: Occurs if an invalid context type is given.
By understanding these module members and their appropriate usage, developers can effectively manage record context in their SuiteScript applications.
Key Takeaways
- The N/recordContext module is essential for accessing record contexts in SuiteScript.
- The
getContextmethod can retrieve contexts for both loaded and unloaded records. - Proper use of parameters is critical to preventing errors during context retrieval.
Frequently Asked Questions (4)
Can the `recordContext.getContext` method be used in both client and server scripts?
What happens if both a loaded record and a record ID/record type are provided when using the `getContext` method?
What should I provide as parameters when retrieving the context for an unloaded record in SuiteScript?
Is the `contextTypes` parameter mandatory when using the `getContext` method?
Was this article helpful?
More in SuiteScript
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- Set Sublist Field Values in SuiteScript 2.x for Record Management
Set sublist field values in SuiteScript 2.x for effective record management using standard and dynamic modes.
- Setting Field Values in SuiteScript for Effective Record
Learn to set field values in SuiteScript effectively, troubleshooting common errors and understanding data types.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category