Find Plug-in Implementations
The following sample shows an implementation of a custom plug-in interface. To test this sample, you need a custom plug-in type with a script ID of customscript_magic_plugin
and an interface with a single method, int doTheMagic(int, int)
.
This script sample uses the define
function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require
function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript 2.x Global Objects.
/**
* @NApiVersion 2.x
* @NScriptType plugintypeimpl
*/
define(function() {
return {
doTheMagic: function(operand1, operand2) {
return operand1 + operand2;
}
}
});
The following Suitelet iterates through all implementations of the custom plug-in type customscript_magic_plugin
. For the plug-in to be recognized, the Suitelet script record must specify the plug-in type on the Custom Plug-in Types subtab.
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define(['N/plugin'], function(plugin) {
function onRequest(context) {
var impls = plugin.findImplementations({
type: 'customscript_magic_plugin'
});
for (var i = 0; i < impls.length; i++) {
var pl = plugin.loadImplementation({
type: 'customscript_magic_plugin',
implementation: impls[i]
});
log.debug('impl ' + impls[i] + ' result = ' + pl.doTheMagic(10, 20));
}
var pl = plugin.loadImplementation({
type: 'customscript_magic_plugin'
});
log.debug('default impl result = ' + pl.doTheMagic(10, 20));
}
return {
onRequest: onRequest
};
});