Calling a RESTlet from a SuiteLet
A RESTlet script in NetSuite is very much like a web service in a web application.
The following example illustrates how to call a RESTlet script from a SuiteLet script in NetSuite.
Note: The 'https' & 'url' modules must be included in the script.
/** * @NApiVersion 2.0 * @NScriptType ClientScript * @NModuleScope SameAccount */ define(['N/runtime', 'N/https', 'N/url'], /** * @param {runtime} runtime * @param {https} https * @param {url} url */ function(runtime, https, url) { ... }
Calling the RESTlet:
// set a value for the employee code, // this is the value we'll be passing to the RESTlet var empCode = 'ABCD'; // build our RESTlet URL var restletUrl = url.resolveScript({ scriptId : 'customscript_sdr_rl_validate_emp_code', deploymentId : 'customdeploy_sdr_rl_validate_emp_code' }); // call the RESTlet, in this case, passing a parameter called "sdr_emp_code" var response = https.get({ url : restletUrl + '&sdr_emp_code=' + empCode }); // check the response if (response.body == 'invalid') { // perform some action if the employee code is invalid }
Inside the RESTlet:
function doGet(params) { // get the employee code from the parameter that was passed in var empCode = params.sdr_emp_code; // determine if the employee code is invalid if (empCode == 'x') { return 'invalid'; } return 'valid'; }