Thursday, November 29, 2018

Sort SuiteScript Search Results by Two Columns

You can sort the results of a SuiteScript search by Two Columns.

Here is a Script Snippet to sort search results by Last Name and then by First Name:

var columns = [];

var column_firstname = nlobjSearchColumn('lastname');
var column_lastname  = nlobjSearchColumn('firstname');
var column_email     = nlobjSearchColumn('email');

column_firstname.setSort();
column_lastname.setSort();

columns.push(column_firstname);
columns.push(column_lastname);
columns.push(column_email);

var searchResults = nlapiSearchRecord('customer', null, null, columns);

If you wanted to Sort by First Name first then by Last Name, push the Last Name first into the columns array

columns.push(column_lastname);
columns.push(column_firstname);
columns.push(column_email);

No comments:

Post a Comment