Accessing SCA Data in Custom Content Types for SuiteCommerce
Access SCA data in SuiteCommerce with custom content types, enabling dynamic content management and user event handling in your applications.
TL;DR Opening
Accessing SCA data is crucial for developers implementing custom content types (CCT) in SuiteCommerce, allowing for dynamic content management and user interaction.
Overview
When building custom content types (CCT) in SuiteCommerce Advanced (SCA), it’s essential to manage data effectively. Although custom modules can be loaded as a Content Control Template (CCT) within Site Management Tools (SMT), the initial implementation lacks data until paired with the appropriate view files.
Importance of the View File
The view file is necessary for:
- Accessing data related to items, item lists, products, or categories.
- Listening to user events and interpreting data interactions.
- Specifying the context for rendering templates with the relevant data.
CCT Module Initialization
The CustomContentType.Base.View.js file is included in your SCA source files. This file extends the BackboneView.js, initializes the CCT settings, and serves as the base class for extending custom CCT modules. You must create your custom view by extending CustomContentType.Base.View.js.
Accessing SCA Data
Each view can access SCA data about:
- Items
- Item lists
- Products
- Categories
It's important to note that for your templates to utilize this data, each view must implement the getContext() method.
Utilizing the contextDataRequest
If your CCT needs data beyond what is tied to custom record fields, you can utilize the contextDataRequest array to access SCA objects. Here are some key contextData objects:
| Data Type | JavaScript File (SCA 2019.1 and Earlier) | TypeScript File (SCA 2019.2 and Later) | Description |
|---|---|---|---|
category | Facets.Browse.View.js | Facets.Browse.View.ts | Data of the current category |
item | ProductDetails.Base.View.js | ProductDetails.Base.View.ts | Data for the item on the Product Details page |
itemlist | Facets.Browse.View.js | Facets.Browse.View.ts | Current item list in search page |
product | ProductDetails.Base.View.js | ProductDetails.Base.View.ts | Data for the product on the Product Details page |
By default, when adding SCA content via SMT Admin, the validateContextDataRequest method checks for all requested contexts. Sometimes, contextData can request optional information that might not exist, which could result in a failed validation. To handle this, override the validateContextDataRequest method to always return true.
Example Code for ImageViewer CCT
Here’s an example of how to structure your code when creating the ImageViewer CCT to request the item object:
1//... 2, contextDataRequest: ['item'] 3, validateContextDataRequest: "text-purple-400">function() { 4 "text-purple-400">return true; 5} 6, getContext: "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
Each associated custom record defined within a settings object is received by the template. You need to specify fields by their Field ID. For example, within the getContext() method, you can declare:
custrecord_sc_cct_iv_valign- for vertical text alignment.custrecord_sc_cct_iv_text- for display text.custrecord_sc_cct_iv_imageurl- for the image URL.
Example Code for Custom Record Field Access
Here’s how you can implement it in the getContext():
1//... 2, getContext: "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//...Creating Your View
To create and set up your view:
- Create a new JavaScript or TypeScript file in your CCT module's JavaScript directory, naming it logically based on your module.
- Define the view's dependencies clearly to leverage essential files.
- Implement the view according to your CCT requirements and save your new file.
This effective structure facilitates the seamless integration of your custom content type data management in SuiteCommerce applications.
Who This Affects
This documentation is relevant to the following roles:
- Developers: Implement custom content types to enhance eCommerce functionality.
- Administrators: Manage and configure custom modules using SMT.
- Site Managers: Enable dynamic content delivery through CCT integrations.
Key Takeaways
- Each view in SuiteCommerce must implement the
getContext()method to access data. - You can retrieve additional context data by utilizing
contextDataRequest. - Overriding the
validateContextDataRequestmethod is essential for handling optional data requests. - Custom records are defined in the
settingsobject, accessible in the template. - Proper setup of module files is crucial for successful CCT implementation.
Source: This article is based on Oracle's official NetSuite documentation.
Frequently Asked Questions (4)
How do I access data related to items, item lists, products, or categories in a custom content type for SuiteCommerce?
What is the role of the 'validateContextDataRequest' method in a SuiteCommerce custom content type?
Can I use TypeScript when creating custom content types in SuiteCommerce?
How can I access custom record fields within my SuiteCommerce custom content type?
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.
