Modules

filter

 

Objects/Functions

module (N/search)

SuiteScript 2.0

Column.setWhenOrderedBy(options)

{Column}.setWhenOrderedBy({name: {string},join: {string}})

N/search Module
Column.setWhenOrderedBy()
Method Description: Returns the search column for which the minimal or maximal value should be found when returning the search.Column value. For example, can be set to find the most recent or earliest date, or the largest or smallest amount for a record, and then the search.Column value for that record is returned. You can only use this method if you use MIN or MAX as the summary type on a search column with the Result.getValue(options) method.
Returns: search.Column
Supported Script Types: All script types For more information, see SuiteScript 2.0 Script Types.
Governance: None
Module: N/search Module
Since: 2015.2
Search NetSuite - https://system.netsuite.com/app/help/helpcenter.nl?search=Column.setWhenOrderedBy(options)

Example:

// Code Example 1
// Add additional code
//...
// Execute a customer search that returns the amount of the most recent sales order per customer

var filters = [];
var columns = [];

filters[0] = search.createFilter({
name: 'recordtype',
join: 'transaction',
operator: search.Operator.IS,
values: 'salesorder'
});
filters[1] = search.createFilter({
name: 'mainline',
join: 'transaction',
operator: search.Operator.IS,
values: true
});

columns[0] = search.createColumn({
name: 'entityid',
summary: search.Summary.GROUP
});
columns[1] = search.createColumn({
name: 'totalamount',
join: 'transaction',
summary: search.Summary.MAX
});

columns[1].setWhenOrderedBy({
name: 'trandate',
join: 'transaction'
});

var mySearch = search.create({
type: 'customer',
filters: filters,
columns: columns
});
var resultsArray = mySearch.run().getRange({
start: 0,
end: 100
});
//...
// Add additional code

//SOURCE: https://system.netsuite.com/app/help/helpcenter.nl?fid=section_457130065917.html