Wednesday, March 27, 2019

Simple Pagination of a Sublist in a Suitelet

The following code creates a Suitelet that displays a Sublist from a saved search with a simple pagination using a dropdown.
The Suitelet interacts references a Client script for the fieldChange operations done when the value of the dropdown is changed.

Suitelet Script:

 * @param {nlobjRequest}  request Request object
 * @param {nlobjResponse} response Response object
 * @returns {Void} Any output is written via response object
function suitelet(request, response) {

 var form = nlapiCreateForm('Web Store Items');

 // a simple drop down to select which records from the result to display
 var fld = form.addField('custpage_rows', 'select', 'View Row Numbers');
 fld.addSelectOption('3', '1 to 3');
 fld.addSelectOption('6', '4 to 6');
 fld.addSelectOption('9', '7 to 9');

 // sets a client script
 var rowsPerPage = 3;
 var rowCount = request.getParameter('custpage_rows');
 if (null == rowCount || rowCount == '') {
  rowCount = rowsPerPage;

 var rowCountURL = request.getParameter('param_rowCount');
 if (null != rowCountURL && rowCountURL != '') {
  rowCount = rowCountURL;

 form.addSubTab('tab1', 'Web Store Items');
 var sublist = form.addSubList("custpage_sublist", "staticlist", "Sublist",
 sublist.addField('itemid', 'text', 'Name');
 sublist.addField('displayname', 'text', 'Display Name');
 sublist.addField('salesdescription', 'text', 'Description');
 sublist.addField('type', 'text', 'Type');
 sublist.addField('baseprice', 'currency', 'Base Price');
 // the records to be displayed are from a saved search
 var s = nlapiLoadSearch('item', 'customsearch22');
 var resultSet = s.runSearch();

 // only display rows from the search result that matches the value in the drop down
 var results = resultSet.getResults(rowCount - rowsPerPage, rowCount);
 for ( var i = 0; results != null && i < results.length; i++) {
  var row = i + 1;
  searchresult = results[i];
  sublist.setLineItemValue('itemid', row, searchresult.getValue('itemid'));
  sublist.setLineItemValue('displayname', row, searchresult.getValue('displayname'));
  sublist.setLineItemValue('salesdescription', row, searchresult.getText('salesdescription'));
  sublist.setLineItemValue('type', row, searchresult.getValue('type'));
  sublist.setLineItemValue('baseprice', row, searchresult.getValue('baseprice'));



Client Script:

 * The recordType (internal id) corresponds to the "Applied To" record in your script deployment.
 * @appliedtorecord recordType
 * @param {String} type Sublist internal id
 * @param {String} name Field internal id
 * @param {Number} linenum Optional line item number, starts from 1
 * @returns {Void}
function clientFieldChanged(type, name, linenum) {

 if (name == 'custpage_rows') {
  var rowCount = nlapiGetFieldValue('custpage_rows');
  var url =;
  if (url.indexOf('&param_rowCount') > 0) {
   // Remove the previous value of the parameter: param_rowCount
   url = url.substring(0, url.indexOf('&param_rowCount'));
  // The code below refreshes the page and passes the value of the dropdown
  // in the URL as a parameter = url + '&param_rowCount=' + rowCount;


DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Netsuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.

Netsuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Netsuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.

Netsuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code


No comments:

Post a Comment