Creating the Default Implementation for a Custom Plug-in
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.1. To get started with SuiteScript, see SuiteScript 2.1.
An implementation fully defines an interface’s functions and contains the logic they run. When you're developing a plug-in, you must define a default implementation to set up the custom plug-in script’s default logic. The default implementation is written as an independent JavaScript file.
Each function in the interface must be fully defined in the default implementation.
Programming Note: Log messages written by using N/log Module functions (log.debug, log.error, log.audit, log.emergency) in a plug-in implementation are tracked on the script record that calls the plug-in. The log level is determined by that script's deployment. You can see log messages by viewing the execution log of the script that called the plug-in. For more information about script deployment, see SuiteScript 2.x Entry Point Script Creation and Deployment.
SuiteScript 2.x Custom Plug-in Default Implementation Example
The following is a SuiteScript 2.x example of a default implementation:
/**
* @NApiVersion 2.x
* @NScriptType plugintypeimpl
*/
define(function() {
return {
doTheMagic: function(inputObj) {
var operand1 = parseFloat(inputObj.operand1);
var operand2 = parseFloat(inputObj.operand2);
if (!isNaN(operand1) && !isNaN(operand2)) {
return operand1 + operand2;
}
},
otherMethod: function() {
return 'sample';
}
}
});
This sample default implementation fully defines the doTheMagic
function. When you call it in the custom plug-in script, this function accepts two numbers, operand1
and operand2
, and adds them together to return a result.
Related Topics
- Custom Plug-in Overview
- Custom Plug-in Development
- Creating a Custom Plug-in Interface
- Adding the Default Implementation to NetSuite
- Instantiating a Custom Plug-in Script in SuiteScript 2.x
- Instantiating a Custom Plug-in Script in SuiteScript 1.0
- Adding a Script that Instantiates a Custom Plug-in to NetSuite
- Bundling a Custom Plug-in
- Custom Plug-in Creation