To call the extensibility API, begin by accessing the SC object, which is globally available in SuiteCommerce. Through SC, you can access various components and utilities provided by NetSuite’s extensibility framework. This object enables you to interact with the SCA environment and test your extensions directly from the browser console.
For example, calling a component through SC in the console can look like this:
javascript SC.MyComponent
This command retrieves the MyComponent object if it has been defined and is available through the SC global.
The mountToApp Function and Application Container
The mountToApp function is crucial when initializing or attaching custom components to the SuiteCommerce application. In SCA, each extension or component is mounted to a primary application container, commonly referred to as application or container, which manages the lifecycle and scope of components within the SuiteCommerce environment.
How mountToApp Works
The mountToApp function takes the application instance (container) as a parameter. This application instance is responsible for mounting the component at specific points within the app, linking it with predefined hooks, routes, or entry points in the SuiteCommerce infrastructure.
Here’s a basic example of how to use mountToApp within an extension:
javascript
define(
'MyModule.MyComponent',
['MyModule.MyComponent.View'],
function (MyComponentView) {
'use strict';
return {
mountToApp: function (application) {
// The component is mounted to the application container here
var myComponent = new MyComponentView();
// Optionally, register component or routes here
application.getLayout().showContent(myComponent);
// Return the component instance
return myComponent;
}
};
}
);
In this code:
applicationis passed as an argument tomountToApp, allowing the component to attach itself to the SuiteCommerce application.- A new instance of
MyComponentViewis created and displayed in the main layout of the application usingshowContent.
Using mountToApp with Console Testing
To test and call your custom component through the console, make sure your module is loaded and available within the SC global. You can then call SC.MyModule.MyComponent.mountToApp(SC.Application('Shopping')) directly in the browser console to mount the component within the application context, assuming MyModule is your module namespace.
Summary
Using SC as the entry point for accessing SuiteCommerce’s extensibility API and leveraging mountToApp with an application container makes adding custom components straightforward. This approach lets developers test, initialize, and manage component lifecycles directly from the console and the extensibility framework. With these methods, you can streamline component management and enhance SuiteCommerce Advanced’s modularity and extensibility.