Write Your First Suitelet
Note:
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.
The following sample creates a Suitelet that shows an empty page with a Hello World header.
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define([], function() {
function onRequest(context) {
var html = '<html><body><h1>Hello World</h1></body></html>';
context.response.write(html);
context.response.setHeader({
name: 'Custom-Header-Demo',
value: 'Demo'
});
}
return {
onRequest: onRequest
};
});
The following screenshot shows the output of this script.
