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.

·4 min read·View Oracle Docs

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 TypeJavaScript File (SCA 2019.1 and Earlier)TypeScript File (SCA 2019.2 and Later)Description
categoryFacets.Browse.View.jsFacets.Browse.View.tsData of the current category
itemProductDetails.Base.View.jsProductDetails.Base.View.tsData for the item on the Product Details page
itemlistFacets.Browse.View.jsFacets.Browse.View.tsCurrent item list in search page
productProductDetails.Base.View.jsProductDetails.Base.View.tsData 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:

javascript
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():

javascript
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:

  1. Create a new JavaScript or TypeScript file in your CCT module's JavaScript directory, naming it logically based on your module.
  2. Define the view's dependencies clearly to leverage essential files.
  3. 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 validateContextDataRequest method is essential for handling optional data requests.
  • Custom records are defined in the settings object, 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?
To access data related to items, item lists, products, or categories, you must implement the 'getContext()' method in your custom content type's view file. This method allows the view to utilize relevant SCA data for rendering templates.
What is the role of the 'validateContextDataRequest' method in a SuiteCommerce custom content type?
The 'validateContextDataRequest' method is responsible for checking all requested context data. If some requests for optional information might not return data, you can override this method to always return 'true' and handle such cases gracefully.
Can I use TypeScript when creating custom content types in SuiteCommerce?
Yes, you can use TypeScript when creating custom content types in SuiteCommerce. For instance, post-SCA 2019.2, TypeScript files like 'ProductDetails.Base.View.ts' are available to manage data related to products and categories.
How can I access custom record fields within my SuiteCommerce custom content type?
You can access custom record fields within your CCT by defining them in the 'settings' object and specifying their Field IDs within the 'getContext()' method. This will allow the template to receive and utilize these custom records.
Source: Accessing SCA Data 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 →