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.
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 Name | Type | Description |
|---|---|---|
Sort.ascending | boolean | Indicates if the sort is in ascending order when true. |
Sort.caseSensitive | boolean | If set to true, the sort will be case sensitive. |
Sort.locale | query.SortLocale (read-only) | Specifies the locale of the sort. |
Sort.nullsLast | boolean | When true, places null values at the end of the sort order. |
Sort.order | number | Determines 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
// Create a default Sortvar mySort = workbook.createSort({});Custom Descending Sort Example
1// Create a custom descending Sort2var mySort = workbook.createSort({3 ascending: false,4 caseSensitive: true,5 nullsLast: true,6 locale: query.SortLocale.US_EN7});Accessing Sort Properties
To access properties of a Sort object after loading a workbook, you can use:
1// Load a workbook by ID2var myWorkbook = workbook.load({3 id: myWorkbookId4});5 6// Retrieve the sort properties from a table column7var mySort = myWorkbook.tables[0].columns[0].sort;8 9log.audit({10 title: 'Sort.ascending = ',11 details: mySort.ascending12});13 14log.audit({15 title: 'Sort.caseSensitive = ',16 details: mySort.caseSensitive17});18 19log.audit({20 title: 'Sort.locale = ',21 details: mySort.locale22});23 24log.audit({25 title: 'Sort.nullsLast = ',26 details: mySort.nullsLast27});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.
Frequently Asked Questions (4)
What components can the Sort object be applied to in SuiteScript?
How do you create a custom descending Sort object in SuiteScript?
What happens when the 'nullsLast' property is set to true in a Sort object?
Can the 'Sort.locale' property be modified once a Sort object is created?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
