Instantiating a Custom Plug-in Script in SuiteScript 1.0
To create your own custom plug-ins and implementation scripts, you need some JavaScript 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.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.
The term “class name” is a misleading. When you create a new instance of an implementation, you're instantiating a delegate, not an object.
Instantiate the implementation using the new
keyword and the Class Name from the custom plug-in type record. The constructor has one optional parameter, implementationId
, which 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);
You can instantiate active implementations only 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:
-
You can directly specify the implementation your code is instantiating.
-
You can instantiate based on the Deployment Model setting on the Custom Plug-in Type record. In other words, you can instantiate the implementations that are currently active in the customer’s account.
Instantiating a Specific Implementation
Pass one of the following arguments for implementationId
to instantiate a specific implementation.
-
default
– Pass this string argument to create an instance of the default implementation. Be sure to enclose the argument in single quotes. See Calling a Default Implementation’s Functions for an example. -
The ID entered on the New Plug-in Implementation record – Pass this string argument to create an instance of a specific alternate implementation. Be sure to enclose the argument in single quotes. See Calling an Alternate Implementation’s Functions for an example.
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.
-
No argument – If you don't pass an argument, the active implementation is instantiated. Use this option if the Deployment Model field is set to Allow Single.
-
An array, returned by
getImplementations
, that contains all active implementations – Use this option if the Deployment Model field is set to Allow Multiple. You must use thegetImplementations
method to instantiate the implementations. For more information and an example, see Discovering Active Implementations.
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 from the New Plug-in Implementation record as an argument.
Make sure that the Deployment Model on the custom plug-in type record is 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 doesn't directly know about 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 the Deployment Model field on the Custom Plug-in Type record is set to Allow Multiple and you don't specify which implementation to instantiate, you'll need to 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 the Default Implementation for a Custom Plug-in
- 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 an Alternate Implementation to NetSuite