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.
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?
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 Platform
- Style Object Members for Workbook API in NetSuite
The Style object provides customizable properties for workbook formatting in NetSuite, enhancing report and visualization functionality.
- Asynchronous HTTP Requests with SuiteScript Promises
Use SuiteScript to send asynchronous HTTP requests with promises for efficient error handling and response processing.
- Setting Sublist Field Values in SuiteScript
Set values for sublist fields in SuiteScript using the setSublistValue method. Understand required parameters and error handling.
- In This Help Topic
Explore N/log module guidelines, log levels, and script execution logs for efficient logging in SuiteScript.
Advertising
Reach Platform Professionals
Put your product in front of NetSuite experts who work with Platform every day.
Sponsor This Category