N/recordContext Module Members

Explore N/recordContext module members, including methods and their types for SuiteScript development.

·2 min read·View Oracle Docs

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 NameTypeReturn Type / Value TypeSupported Script TypesDescription
recordContext.RecordContextObjectObject (read-only)Client and server scriptsContains key-value pairs that represent context types and their values.
recordContext.getContext(options)MethodrecordContext.RecordContextClient and server scriptsReturns the record context object for a record.
recordContext.ContextTypeEnumenum (read-only)Client and server scriptsHolds 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 recordType and recordId parameters:

    javascript
    recordContext.getContext({
    recordType: 'customer',
    recordId: '123'
    });
  • For Loaded Records: If the record is already loaded in your script, use the record parameter:

    javascript
    recordContext.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 getContext method can retrieve contexts for both loaded and unloaded records.
  • Proper use of parameters is critical to preventing errors during context retrieval.

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

Frequently Asked Questions (4)

Can the `recordContext.getContext` method be used in both client and server scripts?
Yes, the `recordContext.getContext` method can be used in both client and server scripts according to its supported script types configuration.
What happens if both a loaded record and a record ID/record type are provided when using the `getContext` method?
If both a loaded record and a record ID/record type are provided, the `getContext` method will throw a `MUTUALY_EXCLUSIVE_ARGUMENT` error.
What should I provide as parameters when retrieving the context for an unloaded record in SuiteScript?
For an unloaded record, you need to provide the `recordType` and `recordId` as parameters to the `getContext` method.
Is the `contextTypes` parameter mandatory when using the `getContext` method?
No, the `contextTypes` parameter is optional when using the `getContext` method. It specifies the types of contexts to retrieve if needed.
Source: N/recordContext 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 Platform

View all Platform articles →