• : 1-877-596-8218
  • : sales@aecc.ca
# # #

Create a Simple SuiteLet.

SuiteLet is a powerful extension of NetSuite SuiteScript, it allows user to build customize page with back-end logics.
SuiteLet is a server side script running on the server. To start with SuiteLet, let’s create a simple SuiteLet and add on button on a customer record, when the record is clicked, a suiteLet will open to display the bins related to this customer

In the first step, we need to create a user event before load script to add a button to the customer record. When this button is clicked, this user event script open the suiteLet and passes necessary parameters within the URL to the suiteLet.

var CONTEXT = nlapiGetContext();
function beforeLoad_createBinButton(type, form, request) {
   var stLoggerTitle = 'beforeLoad_createBinButton';
   nlapiLogExecution('DEBUG', stLoggerTitle, '||| --- >>> Starting ' + stLoggerTitle + ' <<< --- |||');
   form.addButton('custpage_displaybins', 'Bins', 'executeSuiteletForm()');
   nlapiLogExecution('DEBUG', stLoggerTitle, '||| --- >>> Exiting ' + stLoggerTitle + ' <<< --- |||');

function executeSuiteletForm() {
   var customerInfo = nlapiLookupField('customer',nlapiGetRecordId(),['internalid', 'entityid']);
   var customerID = customerInfo['internalid'];
   var entityID = customerInfo['entityid']
   nlapiLogExecution('debug', 'customer ID is ', customerID);
   var URL = nlapiResolveURL('Suitelet', 'customscript_create_bin_list', 'customdeploy_create_bin_list');
   var URLParam = '&customerID=' + customerID + '&entityID=' + entityID;
   var suiteLetURL = URL+ URLParam;

In this example, the customer ID and entity ID are passing into along with the request URL when calling the suiteLet.

The following code demonstrates the script to create a SuiteLet which make a search in the system and list all bins related to this customer in a sublist.

* Created by Zhuang Liu on 2016-12-29.
* SuiteLet to display the list of bins for customer
function suitelet_displayCustomerBin(request, response){
   nlapiLogExecution('debug', '----- Display Bins SuiteLet runs -----');
   if(request.getMethod() == 'GET'){
       var customerID = request.getParameter('customerID');
       var customerName = nlapiLookupField('customer',customerID,'altname');
       var entityID = request.getParameter('entityID');
       //----- Create Form and set body field
       var form = nlapiCreateForm('Bins List');
       form.addField('custpage_customer_name', 'text', 'Customer Name').setDefaultValue(customerName);//.setDisplayType('inline');
       form.addField('custpage_customer_id', 'text', 'Customer Internal ID').setDefaultValue(customerID);
       form.addField('custpage_customer_entityid', 'text', 'Customer Entity ID').setDefaultValue(entityID);

       //----search bins and write to sublist-----
       var binSublist = form.addSubList('custpage_binsublist', 'list', 'Bins');
       binSublist.addField('custpage_location', 'select', 'Location', 'location').setDisplayType('inline');
       binSublist.addField('custpage_aptos_actual_bin', 'select', 'Aptos Actual Bin Name', 'customlist_aptos_bins').setDisplayType('inline');
       binSublist.addField('ccustpage_bin', 'select', 'Bin Number', 'bin').setDisplayType('inline');
       for (var i = 1; i <= bins.length; i++) {
           var bin = bins[i - 1];
           binSublist.setLineItemValue('custpage_location', i, bin.locationid);
           binSublist.setLineItemValue('custpage_aptos_actual_bin', i, bin.actualbinname);
           binSublist.setLineItemValue('ccustpage_bin', i, bin.internalid);

       // ----- Redirect to SuiteLet ------
       var params = new Array();
       params['customerID'] = customerID;
       params['entityID'] = entityID;
       nlapiSetRedirectURL ('SUITELET' , 'customscript_create_bin_list' , 'customdeploy_create_bin_list',false, params);