PageRange Object Members in SuiteScript for Developers

The PageRange object in SuiteScript provides parameters for managing query results, enhancing how developers handle paginated queries.

·3 min read·View Oracle Docs

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 NameReturn TypeSupported Script TypesDescription
PageRange.indexnumber (read-only)Client and server scriptsIndicates the index for this page range.
PageRange.sizenumber (read-only)Client and server scriptsSpecifies 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:

suitescript
1// Add additional code
2...
3var myCustomerQuery = query.create({
4 type: query.Type.CUSTOMER
5});
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 iterator
14var 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 loop
23for (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 code

This 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.


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

Key Takeaways

  • The PageRange object helps manage paginated query results effectively.
  • Contains two main read-only properties: index and size.
  • 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?
The page size can be retrieved using the 'PageRange.size' property in your script. This property indicates the number of query result rows in the current page range.
What script types support the use of the PageRange object in SuiteScript?
The PageRange object is supported in both client and server scripts, allowing it to be used across different environments within NetSuite.
Do I need any specific permissions to use the PageRange object in SuiteScript?
The article does not mention specific permissions required to use the PageRange object, so it is assumed to be available as part of standard SuiteScript capabilities.
Can the PageRange object be used to navigate through all pages of a large dataset?
Yes, the PageRange object is designed for navigating paginated queries, which allows scripts to iterate through all pages efficiently by processing data in manageable chunks.
Source: PageRange 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 Integration

View all Integration articles →