Not logged in - Login
< back

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 'Redirect''https' module& '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 = '123''123';

// 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, we're 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
}