Instantiating a Custom Plug-in Script in SuiteScript 1.0

Important:

To create your own custom plug-ins and implementation scripts, you need some JavaScript coding experience and an understanding of SuiteScript. You should write new custom plug-in scripts in SuiteScript 2.0 or SuiteScript 2.1. To get started with SuiteScript, see SuiteScript 2.x API Reference and SuiteScript 2.1.

Instantiating a Custom Plug-in Implementation

When you create a Custom Plug-in Type record in Adding the Default Implementation to NetSuite, you enter a Class Name for the custom plug-in. Before you can call an implementation’s functions, you must use the class name to create a new instance of the implementation you want to use.

Note:

The term “class name” is a misnomer. When you create a new instance of an implementation, you are instantiating a delegate, not an object.

Instantiate the implementation with the new keyword and the Class Name from the custom plug-in type record. The constructor has one optional parameter, implementationId. The argument you pass in determines which implementation you instantiate. See Instantiating a Specific Implementation and Instantiating an Implementation Based on the Deployment Model for the available arguments.

          var a = new <Class Name>(implementationId); 

        
Important:

Active implementations can only be instantiated after the plug-in is installed by a customer and the plug-in script is executing.

There are two techniques you can use to instantiate an implementation:

Instantiating a Specific Implementation

Pass one of the following arguments for implementationId to instantiate a specific implementation.

Instantiating an Implementation Based on the Deployment Model

Pass one of the following arguments for implementationId to instantiate the implementations that are currently active in the customer’s account. The argument you use depends on the value set for the Deployment Model field. See Adding the Default Implementation to NetSuite for additional information.

Calling a Default Implementation’s Functions

          function useCustomPlugInType()
{
    var a = new DemoPlugInType('default');
    a.doTheMagic({
        operand1: 10,
        operand2: 20
    });
    a.otherMethod();
} 

        

Calling an Alternate Implementation’s Functions

          function useCustomPlugInType()
{
    var b = new DemoPlugInType('customscriptimplementation1');
    b.doTheMagic();
    b.otherMethod();
} 

        

Calling Multiple Implementations’ Functions

In this example, you, the solution provider, create a default implementation and an alternate implementation for the plug-in. The alternate implementation is called by passing the ID entered on the New Plug-in Implementation record as an argument.

Note that the Deployment Model on the custom plug-in type record must be set to Allow Multiple.

          function useCustomPlugInType()
{
    var a = new DemoPlugInType('default');
    a.doTheMagic({
        operand1: 10,
        operand2: 20
    });
    a.otherMethod();

    var b = new DemoPlugInType('customscriptimplementation1');
    b.doTheMagic();
    b.otherMethod();
} 

        

Discovering Active Implementations

After your custom plug-in is installed on a customer’s account, the custom plug-in script has no direct knowledge of the active implementations. If you set the Deployment Model field on the Custom Plug-in Type record to Allow Single, this is not an issue. See Instantiating an Implementation Based on the Deployment Model for additional information.

If Deployment Model field on the Custom Plug-in Type record is set to Allow Multiple and you do not specify which implementation to instantiate, you must use the getImplementations method to instantiate the implementations. The getImplementations method returns an array of active implementations.

          function discoverImplementations()
{
    var x = DemoPlugInType.getImplementations();
    for (var i = 0; i < x.length; i++)
    {
        var t = new DemoPlugInType(x[i]);
        t.doTheMagic();
        t.otherMethod();
    }
} 

        

Related Topics

Custom Plug-in Overview
Custom Plug-in Creation
Custom Plug-in Development
Creating a Custom Plug-in Interface
Creating a Custom Plug-in Default Implementation
Adding the Default Implementation to NetSuite
Instantiating a Custom Plug-in Script in SuiteScript 2.x
Adding a Script that Instantiates a Custom Plug-in to NetSuite
Bundling a Custom Plug-in
Creating a Custom Plug-in Alternate Implementation
Adding the Alternate Implementation to NetSuite

General Notices