Step 3: Set Up Custom Validations (Optional)

Documentation article about Step 3: Set Up Custom Validations (Optional)

·3 min read·View Oracle Docs

Step 3: Set Up Custom Validations (Optional)

Services handle HTTP requests sent by the frontend application to access backend models, which connect to NetSuite. Different releases of SuiteCommerce Advanced (SCA) handle services with significant differences. This section explains how to create a service when implementing the Vinson release of SCA or later.

  • 2019.2 implementations and later provide two options: SuiteScript 2.0 or SuiteScript 1.0. How you go about this depends on the services you are creating. These implementations require Service Controllers.

    Note:

    The following code samples use SuiteScript 1.0 functions and objects only. These examples do not include SuiteScript 2.0 capabilities.

  • SCA implementations of Vinson through 2019.1 require only SuiteScript 1.0. These implementations require Service Controllers.

Note:

If you are using custom services that pre-date the Vinson release of SCA, you can still use them without refactoring your code. SCA offers backward compatibility with any services of implementations prior to Vinson. See Using Pre-Vinson Services with Vinson Release or Later for more information.

Much of the logic required to operate a service is contained in a centralized location within the source files provided. However, you must complete the following steps to create a custom service:

Step 1: Create a Custom [Module].ServiceController

Each service requires a unique [Module].ServiceController. You create this file, where [Module] is the module using the service. To create this custom ServiceController, complete the following tasks:

  1. Create a new [Module].ServiceController file

  2. Define the custom [Module].ServiceController and dependencies

  3. Extend ServiceController

  4. Add custom Validation Options (Optional)

  5. Add HTTP methods (as required for the service)

Create a new [Module].ServiceController file

  1. Create a new file titled [Module].ServiceController.js, where [Module] is the module associated with the service.

  2. Place this service controller file in the module's SuiteScript directory.

Define the custom [Module].ServiceController and dependencies

  1. In your new [Module].ServiceController.js file, define the specific ServiceController and any dependencies.

  2. Include ServiceController as a dependency. How you do this depends on your implementation.

The following code defines the Account Login ServiceController and enables the service to access methods defined in ServiceController and Account.Model.

javascript
1// Account.Login.ServiceController.js - Service to handle the login of a user into the system
2"text-purple-400">define(
3 'Account.Login.ServiceController'
4, [
5 'ServiceController'
6 , 'Account.Model'
7 ]
8, "text-purple-400">function(
9 ServiceController
10 , AccountModel
11 )

Extend ServiceController

  1. [Module].ServiceController must extend ServiceController and include the name property. This property is used when listening to an event. The value of the name property should match the name of [Module].ServiceController.

  2. Use the following example as a guide. The example shows this extension with the name property.

    javascript
    {
    'use strict';
    "text-purple-400">return ServiceController.extend({
    name:'Account.Login.ServiceController'

Add custom Validation Options (Optional)

  1. If you need to define any validation options for the service, include these within return ServiceController.extend.

  2. Use the following example as a guide. This example defines a requirement for the HTTP protocol to be secure before operating this service.

    javascript
    , options: {
    common: {
    requireSecure: true
    }
    }

Add HTTP methods

  1. Within the object returned, define the functions required to handle the HTTP methods for the service. This code reads the HTTP method sent from the frontend (POST, DELETE, GET or PUT).

    For your [Module].ServiceController to function, you must declare each method in lowercase and it must match the name of the HTTP method being used.

  2. Use the following example as a guide. This example defines what the service does on a POST request.

    javascript
    , post: "text-purple-400">function()
    {
    "text-purple-400">return AccountModel.login("text-purple-400">this.data.email, "text-purple-400">this.data.password, "text-purple-400">this.data.redirect)
    }

Using these examples, your custom [Module].ServiceController might look something like this:

Frequently Asked Questions (4)

Does the custom validation setup apply to both SuiteScript 1.0 and 2.0?
The article provides examples using SuiteScript 1.0 only. It does not include capabilities for SuiteScript 2.0 in the provided code samples.
Is it necessary to refactor pre-Vinson custom services to work with the Vinson release or later?
No, it is not necessary to refactor pre-Vinson services. The Vinson release offers backward compatibility with any services from implementations prior to Vinson.
What is the recommended approach for adding HTTP method handling in a custom ServiceController?
HTTP methods should be defined within the object returned by the ServiceController. Each method should be declared in lowercase and must match the HTTP method's name, such as POST, DELETE, GET, or PUT.
Are there any prerequisites for defining a custom Module.ServiceController in SCA?
Yes, you need to create a new Module.ServiceController file and define ServiceController and any dependencies. The ServiceController must be extended, including adding a 'name' property matching the Module.ServiceController's name.
Source: Step 3: Set Up Custom Validations (Optional) 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 General

View all General articles →