Monday, November 26, 2018

Name parameter format for addColumn on nlobjList

The API nlobjSearchColumn can be used to add a field from other records by indicating the 'join' parameter.   

    Syntax : nlobjSearchColumn(name,join,summary)

The search result can be displayed as a list object on a Suitelet. However, an error will come up by indicating the
name paramater for creating a column on the list object.

    Syntax : nlobjList.addColumn(name, type, label, align)

Example : 
    new nlobjSearchColumn('email','customer');
    searchList.addColumn('email','text', 'Email Add', 'LEFT'); // This will have an error.
  
Alternate Solution: For fields from a join, indicate the source record after an underscore(_)
 
    searchList.addColumn('email_customer','text', 'Email Add', 'LEFT');

Thus the proper Syntax for setting the 'name' parameter for the List object:
    
    nlobjList.addColumn(<fieldname>_<recordname>)...
 
Suitelet Sample:  
 ----------------------------------------------
  // Sales Order Search Suitelet
  // Create list
  var searchList = nlapiCreateList('Result list'); 
  var column = searchList.addColumn('internalid','integer', 'Internal ID', 'LEFT');
  searchList.addColumn('currency','text', 'Currency', 'LEFT');    
  searchList.addColumn('amount','currency', 'Amount', 'LEFT');
  
  // Fields from other records
  searchList.addColumn('email_customer','text', 'Email Add', 'LEFT');
  searchList.addColumn('emailpreference_customer','text', 'Email Pref', 'LEFT');
  
  // Filters
  var CSfilters = new Array();
  CSfilters[0] = new nlobjSearchFilter('mainline', null, 'is', 'T');
  CSfilters[1] = new nlobjSearchFilter('amount', null, 'greaterThan', 1000);
 
  //Columns
     var CScolumns = new Array();
  CScolumns[0] = new nlobjSearchColumn('internalid');
  CScolumns[1] = new nlobjSearchColumn('currency');
  CScolumns[2] = new nlobjSearchColumn('amount');
  
  //fields from Customer Record
  CScolumns[3] = new nlobjSearchColumn('email','customer');
  CScolumns[4] = new nlobjSearchColumn('emailpreference','customer');
  
  var salesorder = new Array();
  salesorder = nlapiSearchRecord('salesorder', null, CSfilters, CScolumns);
  
  if (salesorder != null) {
   searchList.addRows( salesorder );
  }else{
   nlapiLogExecution('DEBUG', 'No records found', 'salesorder result = none' );
  }
  response.writePage(searchList);  

 ----------------------------------------------

1 comment: