Creating the Default Implementation for a Custom Plug-in

Important:

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.

Note:

Each function in the interface must be fully defined in the default implementation.

Tip:

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

General Notices