Accessing Custom Record Fields in SuiteCommerce
Access custom record fields within SuiteCommerce templates efficiently, enhancing data interaction through JavaScript and TypeScript.
The Accessing Custom Record Fields functionality allows developers to efficiently interface with custom records in SuiteCommerce, enabling dynamic data rendering and enhanced user experiences.
Accessing Data
Each custom content type (CCT) view can access SuiteCommerce Advanced (SCA) data regarding items, item lists, products, or categories. These data points are accessible to the Document Object Model (DOM) through various SCA modules. Furthermore, each view is capable of returning values for custom record fields associated with the CMS Content Type records.
Important:
To expose this data to your templates, each view must implement the getContext() method.
Accessing SCA Data
If a custom content type requires data not tied to a custom record, you can utilize the contextDataRequest array property to access certain SCA objects. For optimal functionality, ensure that your view is set up to utilize the information that the following contextData objects provide. This assumes the information is already supplied in the DOM at the relevant location where the CCT is placed.
| Context Data Object | View (JavaScript SCA 2019.1 and Earlier) | View (TypeScript SCA 2019.2 and Later) | Description |
|---|---|---|---|
category | Facets.Browse.View.js | Facets.Browse.View.ts | Returns data about the category being navigated |
item | ProductDetails.Base.View.js | ProductDetails.Base.View.ts | Returns data about the item on the Product Details page |
itemlist | Facets.Browse.View.js | Facets.Browse.View.ts | Returns the list of items in the search results |
product | ProductDetails.Base.View.js | ProductDetails.Base.View.ts | Returns data for the product on the Product Details page |
Note:
When adding SCA content in an area using SMT Admin, the application will automatically execute the validateContextDataRequest method to ensure that all requested contexts are valid. In scenarios where optional data is requested and not available, this method might fail. To prevent this, configure your view to override the validateContextDataRequest method so it always returns true.
Example Usage
The ImageViewer CCT requests an item’s name. A simplified implementation of the CCT could be:
1//...,2contextDataRequest: ['item'],3validateContextDataRequest: "text-purple-400">function() {4 "text-purple-400">return true;5},6getContext: "text-purple-400">function getContext() {7 //...;8 "text-purple-400">if ("text-purple-400">this.contextData.item) {9 "text-purple-400">var item = "text-purple-400">this.contextData.item();10 //...;11 }12 //...;13}14//...Accessing Custom Record Fields
By default, when a template renders, it receives a context object that contains each property defined in the linked custom record within a settings object, where you indicate the fields by Field ID.
Example Fields in ImageViewer CCT:
| Field ID | Description |
|---|---|
custrecord_sc_cct_iv_valign | Sets the vertical alignment of a text object |
custrecord_sc_cct_iv_text | Declares the text to display |
custrecord_sc_cct_iv_imageurl | Sets the URL for an image |
In the getContext() method for the ImageViewer CCT, you specify which fields from your custom record correlate with the settings. If the custrecord_sc_cct_iv_valign field requires options from a custom list, your code may look like this:
1//...2getContext: "text-purple-400">function() {3 "text-purple-400">var texts = [],4 imageUrl = '',5 valign = "text-purple-400">this.valign["text-purple-400">this.settings.custrecord_sc_cct_iv_valign] || "text-purple-400">this.valign['3'];6 7 "text-purple-400">var set_text = Utils.trim("text-purple-400">this.settings.custrecord_sc_cct_iv_text),8 set_texts = set_text ? set_text.split('\n') : [],9 set_imageUrl = Utils.trim("text-purple-400">this.settings.custrecord_sc_cct_iv_imageurl);10 11 texts = set_texts.length ? set_texts : texts;12 imageUrl = set_imageUrl ? set_imageUrl : imageUrl;13//...Steps to Create the View:
-
Create a New JavaScript File: In your CCT module's JavaScript directory, create new JavaScript or TypeScript files named appropriately. For example:
../SC.CCT.ImageViewer@0.0.1/JavaScript/SC.CCT.ImageViewer.View.js. -
Define Dependencies: Integrate necessary dependencies in the new view file using either JavaScript or TypeScript syntax, as seen in the previous examples.
-
Build the View: Customize the view in line with your CCT's specifications before saving the view file.
By carefully implementing these steps, developers can effectively access and utilize custom record fields within SuiteCommerce environments, enhancing user engagement through customized templates.
Key Takeaways
- Each CCT view can access SCA data and custom record fields through the
getContext()method. - Utilize the
contextDataRequestproperty for data access beyond custom record fields. - Override the
validateContextDataRequestmethod to ensure flexibility with optional data requests. - Define custom fields within a settings object to tailor user experiences.
Source: This article is based on Oracle's official NetSuite documentation.
Frequently Asked Questions (4)
What is the purpose of the getContext() method in SuiteCommerce templates?
Do I need to override the validateContextDataRequest method?
Which method should I use to access data from SCA modules for a CCT?
How are custom record fields defined in SuiteCommerce templates?
Was this article helpful?
More in SuiteScript
- Scheduling Map/Reduce Script Submissions in NetSuite
Learn how to schedule map/reduce scripts for one-time or recurring submissions in NetSuite, enhancing automation and efficiency.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- Attach and Detach Operations in NetSuite 2026.1
Attach and detach operations for record relationships in NetSuite enhance data management and connectivity.
