Sort Object Members in SuiteScript Workbook API
The Sort object in SuiteScript defines sorting criteria for table columns, 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
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- Setting Field Values in SuiteScript for Effective Record
Learn to set field values in SuiteScript effectively, troubleshooting common errors and understanding data types.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
- Enhancements to SuiteScript User Role Context Clarification
SuiteScript updates clarify the user and role contexts for script executions, improving deployment understanding and management.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category