PageRange Object Members in SuiteScript for Developers
The PageRange object in SuiteScript provides parameters for managing query results, enhancing how developers handle paginated queries.
The PageRange object in SuiteScript enables developers to better manage and navigate paginated query results efficiently. This object contains essential members that provide crucial information about the current page and its size, which are vital for handling larger datasets without degrading performance.
What Is the PageRange Object?
The PageRange object is used to represent a range of query results in a paginated manner within SuiteScript. It’s particularly useful when dealing with large datasets, allowing scripts to process data in chunks.
PageRange Object Members
The PageRange object includes the following members:
| Member Name | Return Type | Supported Script Types | Description |
|---|---|---|---|
PageRange.index | number (read-only) | Client and server scripts | Indicates the index for this page range. |
PageRange.size | number (read-only) | Client and server scripts | Specifies the number of query result rows in this page range. |
Supported Script Types
- Client Scripts: Scripts that run in the user’s browser.
- Server Scripts: Scripts that run on the NetSuite server.
How to Use the PageRange Object
To effectively utilize the PageRange object, developers can incorporate it in their paginated queries. Below is a sample script showcasing the implementation:
1// Add additional code2...3var myCustomerQuery = query.create({4 type: query.Type.CUSTOMER5});6myCustomerQuery.columns = [7 myCustomerQuery.createColumn({ fieldId: 'entityid' }),8 myCustomerQuery.createColumn({ fieldId: 'firstname' }),9 myCustomerQuery.createColumn({ fieldId: 'email' })10];11var myPagedResults = myCustomerQuery.runPaged({ pageSize: 10 });12 13// Fetch results using an iterator14var iterator = myPagedResults.iterator();15iterator.each(function(resultPage) {16 var currentPage = resultPage.value;17 var currentPageRange = currentPage.pageRange;18 log.debug(currentPageRange.size);19 return true;20});21 22// Alternatively, fetch results using a loop23for (var i = 0; i < myPagedResults.pageRanges.length; i++) {24 var currentPage = myPagedResults.fetch(i);25 var currentPageRange = currentPage.pageRange;26 log.debug(currentPageRange.size);27}28...29// Add additional codeThis code demonstrates how to create a customer query, specify columns, run paginated results, and retrieve the size of the current page range.
Key Benefits of Using PageRange
- Efficiency: Reduces memory usage by processing only a subset of results at a time.
- Performance: Improves response times for users when navigating large datasets.
- Flexibility: Provides robust options for developers to respond to various querying needs and complexities.
Conclusion
Utilizing the PageRange object enhances the efficiency of data management within SuiteScript, particularly when dealing with large queries. Understanding its members and how to implement them can significantly contribute to better script performance.
Key Takeaways
- The
PageRangeobject helps manage paginated query results effectively. - Contains two main read-only properties:
indexandsize. - It supports both client and server scripts for flexible querying.
- Implementing it can lead to reduced memory usage and improved performance in scripts.
Frequently Asked Questions (4)
How do I retrieve the current page size using the PageRange object in SuiteScript?
What script types support the use of the PageRange object in SuiteScript?
Do I need any specific permissions to use the PageRange object in SuiteScript?
Can the PageRange object be used to navigate through all pages of a large dataset?
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.
- Set Sublist Field Values in SuiteScript 2.x for Record Management
Set sublist field values in SuiteScript 2.x for effective record management using standard and dynamic modes.
- 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.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category