Component.createSort(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Creates a sort based on the query.Component object. The query.Sort object describes a sort that is placed on a particular query result column or condition.

To create a sort:

Returns

query.Sort

Supported Script Types

Client and server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

None

Module

N/query Module

Parent Object

query.Component

Sibling Object Members

Component Object Members

Since

2018.1

Parameters

Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

options.column

query.Column

required

The query result column that you want to sort by. This value sets the Sort.column property.

options.ascending

boolean

optional

Whether the sort direction is ascending. This value sets the Sort.ascending property.

The default value of this property is true, meaning that the sort direction is ascending. If you want the sort direction to be descending, set this property to false.

options.caseSensitive

boolean

optional

Whether the sort is case sensitive. This value sets the Sort.caseSensitive property.

If a sort is case sensitive (and the sort direction is ascending), rows with column values that start with uppercase letters are listed before rows with column values that start with lowercase letters. If a sort is not case sensitive, uppercase and lowercase letters are treated the same. For example, the following list of items is sorted using a case-sensitive sort with a sort direction of ascending:

  • Banana

  • Orange

  • apple

  • grapefruit

  • kiwi

Here is the same list of items sorted using a regular (not case-sensitive) sort with a sort direction of ascending:

  • apple

  • Banana

  • grapefruit

  • kiwi

  • Orange

The default value of this property is false.

options.locale

string

optional

The locale to use for the sort. This value sets the Sort.locale property.

A locale represents a combination of language and region, and it can affect how certain values (such as strings) are sorted. For example, languages that share the same alphabet may sort characters differently. Use this property to ensure that query results are sorted using locale-specific rules.

Use the appropriate query.SortLocale enum value to pass in your argument. This enum holds all the supported values for this parameter.

options.nullsLast

boolean

optional

Whether query results with null values are listed at the end of the query results. This value sets the Sort.nullsLast property.

The default value of this property is the value of the options.ascending property. For example, if the options.ascending property is set to true, the options.nullsLast property is also set to true.

Syntax

Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/query Module Script Samples.

            // Add additional code
...
var myCustomerQuery = query.create({ type: query.Type.CUSTOMER
}); var mySalesRepJoin = myCustomerQuery.autoJoin({ fieldId: 'salesrep'
}); myCustomerQuery.columns = [ myCustomerQuery.createColumn({ fieldId: 'entityid' }), myCustomerQuery.createColumn({ fieldId: 'id' }), mySalesRepJoin.createColumn({ fieldId: 'entityid' }), mySalesRepJoin.createColumn({ fieldId: 'email' }), mySalesRepJoin.createColumn({ fieldId: 'hiredate' })
]; myCustomerQuery.sort = [ myCustomerQuery.createSort({ column: myCustomerQuery.columns[1] }), mySalesRepJoin.createSort({ column: mySalesRepJoin.columns[0], ascending: false })
]; var resultSet = myCustomerQuery.run();
...
// Add additional code 

          

Related Topics

query.Query
N/query Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices