Models for SuiteCommerce Extensions: SCModel Usage
Leverage SCModel to define data handling in SuiteCommerce extensions. Learn how to create models that validate and fetch data efficiently.
TL;DR
A model in SuiteCommerce extensions manages data handling, such as validation and retrieval. Utilizing the SCModel class, developers can create custom models that integrate seamlessly into the application interface.
What is an SCModel?
In SuiteCommerce, a model allows developers to define how data is validated, saved, or fetched from the server within an extension. When a view requires data, it will typically accept a model to display the information appropriately on the web interface.
Creating a Model Using SCModel
To develop a model, utilize the SCModel class found within the SCModel component. This is part of the extensibility API available since SuiteCommerce 2020.1. If you're working with older versions of SuiteCommerce Advanced, you should employ Backbone's extend() instead.
Note: The SCModel class is unique and does not behave as a traditional component class like others in the extensibility API. For instance, you won't create an instance of SCModel with the getComponent() method. Instead, you declare it as a dependency when defining your model.
Example of a Basic Model
Below is an illustrative example of a basic model using the SCModel class.
1"text-purple-400">define(2 'Vendor.MyExtension.Module.Model',3 [4 'SCModel',5 'Utils'6 ],7 "text-purple-400">function(SCModelModule, Utils) {8 'use strict';9 10 "text-purple-400">var SCModel = SCModelModule.SCModel;11 12 "text-purple-400">function VendorMyExtensionModuleModel () {13 SCModel.call("text-purple-400">this);14 15 "text-purple-400">this.urlRoot = "text-purple-400">function() {16 "text-purple-400">return Utils.getAbsoluteUrl(getExtensionAssetsPath('services/Module.Service.ss'));17 }18 }19 20 VendorMyExtensionModuleModel.prototype = Object.create(SCModel.prototype);21 VendorMyExtensionModuleModel.prototype.constructor = VendorMyExtensionModuleModel;22 23 "text-purple-400">return VendorMyExtensionModuleModel;24 }25);Breakdown of the Model Code
- Module Definition: The
define()statement is first used to specify a unique name for your module and a list of its dependencies. Since we are building onSCModel, this is required to be included. - Constructor Function: The constructor function initializes the model logic. When initializing, it's mandatory to invoke the parent
SCModelconstructor to ensure the model inherits proper properties. - Setting urlRoot: The
urlRootproperty establishes the endpoint for data retrieval. It must be a function returning a string. - Prototype Inheritance: Utilize
Object.create()to set up prototypal inheritance from SCModel, ensuring your custom model inherits the functionalities of SCModel while resetting the constructor property appropriately.
Conclusion
The SCModel class provides a structured way to define and manage data within SuiteCommerce extensions. Thorough understanding and proper implementation can significantly enhance functionality, ensuring data is well-handled and efficiently retrieved.
Who This Affects
- Developers: Those building SuiteCommerce extensions will find this information crucial for effective data management.
- Administrators: Understanding how models work helps in managing extensions and their functionalities effectively.
Key Takeaways
- Models are essential for handling data in SuiteCommerce extensions.
- Use the
SCModelclass for data management in versions from 2020.1 onward. - Properly configure the
urlRootto ensure correct data retrieval.
Source: This article is based on Oracle's official NetSuite documentation.
Frequently Asked Questions (4)
Is the SCModel class applicable to all versions of SuiteCommerce?
How should I define dependencies when creating a model using SCModel?
Can I use getComponent() to instantiate SCModel as I do with other SuiteCommerce components?
How is the urlRoot property configured in an SCModel?
Was this article helpful?
More in Commerce
- Available Items Only Feature in NetSuite 2026.1
Available items only filtering boosts sales efficiency in NetSuite 2026.1 with Intelligent Item Recommendations.
- Commerce Extensions in NetSuite 2026.1
Commerce Extensions in NetSuite 2026.1 enhance performance and user experience in eCommerce.
- Convert Multiple Transaction Line Items into Configured Items in
Enhance transaction processing in NetSuite by converting multiple line items into configured items with improved session handling.
- New SuiteCommerce Features in NetSuite 2026.1
New SuiteCommerce features in NetSuite 2026.1 enhance user experience and improve eCommerce efficiency.
