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' module must be included in the script.

/**
 * @NApiVersion 2.0
 * @NScriptType UserEventScriptClientScript
 * @NModuleScope SameAccount
 */
define(['N/record',define(['N/runtime', 'N/redirect'],'N/https', 'N/url'],
/**
 * @param {record}{runtime} recordruntime
 * @param {redirect}{https} redirecthttps
 * @param {url} url
 */
function(record,function(runtime, redirect)https, url) {
...
}

Calling the RESTlet:

redirect.toSuitelet({
   scriptId     :// 'customscript_sdr_sl_update_emp_notes',set a value for the employee code,
// this is the scriptvalue IDwe'll ofbe passing to the RESTlet
var empCode = '123'

// build our RESTlet URL
var restletUrl = url.resolveScript({
   scriptId     : 'customscript_sdr_rl_validate_emp_code',
   deploymentId : 'customdeploy_sdr_sl_update_emp_notes', 'customdeploy_sdr_rl_validate_emp_code'
});

// this is the deployment ID of the RESTlet
   parameters   : { // these are the parameters that are passed tocall the RESTlet, thein namesthis ofcase, whichwe're canpassing bea anything
      sdr_name  :parameter employee.getValue('entityid'),
      sdr_notescalled 'sdr_emp_code'
var response = https.get({
   url : employee.getValue('comments'),
      sdr_empidrestletUrl :+ employee.id
   }'&sdr_emp_code=' + empCode
});

// check the response
if (response.body == 'invalid') {
   // perform some action if the employee code is invalid
}