Sort Object Members in SuiteScript Workbook API

The Sort object in SuiteScript helps to define sorting criteria for table columns and dimensions, enhancing data presentation in NetSuite.

·2 min read·View Oracle Docs

The Sort object in SuiteScript provides developers with a robust way to specify how data is sorted within various components such as table columns, dimensions, or measures. This feature is essential for ensuring that end-users can view data in a meaningful order, greatly impacting the usability of reports and dashboards.

What Members Does the Sort Object Include?

The workbook.Sort object has several members that control the sorting behavior:

Member NameTypeDescription
Sort.ascendingbooleanIndicates if the sort is in ascending order when true.
Sort.caseSensitivebooleanIf set to true, the sort will be case sensitive.
Sort.localequery.SortLocale (read-only)Specifies the locale of the sort.
Sort.nullsLastbooleanWhen true, places null values at the end of the sort order.
Sort.ordernumberDetermines the order in which items are sorted.

How to Create a Sort Object

You can create a sort object using the workbook.createSort(options) function. Below are some examples to demonstrate its use:

Default Sort Example

suitescript
// Create a default Sort
var mySort = workbook.createSort({});

Custom Descending Sort Example

suitescript
1// Create a custom descending Sort
2var mySort = workbook.createSort({
3 ascending: false,
4 caseSensitive: true,
5 nullsLast: true,
6 locale: query.SortLocale.US_EN
7});

Accessing Sort Properties

To access properties of a Sort object after loading a workbook, you can use:

suitescript
1// Load a workbook by ID
2var myWorkbook = workbook.load({
3 id: myWorkbookId
4});
5
6// Retrieve the sort properties from a table column
7var mySort = myWorkbook.tables[0].columns[0].sort;
8
9log.audit({
10 title: 'Sort.ascending = ',
11 details: mySort.ascending
12});
13
14log.audit({
15 title: 'Sort.caseSensitive = ',
16 details: mySort.caseSensitive
17});
18
19log.audit({
20 title: 'Sort.locale = ',
21 details: mySort.locale
22});
23
24log.audit({
25 title: 'Sort.nullsLast = ',
26 details: mySort.nullsLast
27});

Conclusion

Optimizing data sorting not only enhances the aesthetic presentation of reports but also improves user experience by allowing quick insights into data. Utilizing the Sort object effectively will ensure that developers can tailor data views for their audience.

Source: This article is based on Oracle's official NetSuite documentation.

Frequently Asked Questions (4)

What components can the Sort object be applied to in SuiteScript?
The Sort object can be applied to table columns, dimensions, and measures within SuiteScript to specify sorting criteria.
How do you create a custom descending Sort object in SuiteScript?
You can create a custom descending Sort object by using the `workbook.createSort` function with the `ascending` property set to `false`, and optionally setting other properties like `caseSensitive`, `nullsLast`, and `locale`.
What happens when the 'nullsLast' property is set to true in a Sort object?
When the 'nullsLast' property is set to true, the Sort object will place null values at the end of the sort order.
Can the 'Sort.locale' property be modified once a Sort object is created?
No, the 'Sort.locale' property is read-only and cannot be modified once the Sort object is created.
Source: Sort Object Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Platform

View all Platform articles →