SuiteQL Pagination: How to Query More Than 1,000 Rows
Learn the difference between runSuiteQL() and runSuiteQLPaged() in NetSuite, including result limits, pagination, mapped results, and building lookup caches.
Date
October 29, 2026
Read
4 min
When working with SuiteQL in NetSuite, you may need to retrieve more records than a single query execution returns.
The N/query module provides two methods for executing SuiteQL:
query.runSuiteQL() for unpaged results.
query.runSuiteQLPaged() for retrieving results across multiple pages.
Understanding the difference is useful when building data lookups, processing large record sets, or creating caches for SuiteScript automation.
Running a Basic SuiteQL Query
The query.runSuiteQL() method executes a SuiteQL statement and returns a result set.
For example:
const sql = `
SELECT
id,
itemid
FROM
item
WHERE
id = ? OR id = ?
`;
const myQueryResult = query.runSuiteQL({
query: sql,
params: [123, 456]
});
const mappedResults = myQueryResult.asMappedResults();
The question marks (?) are placeholders for the values supplied through the params array.
Using parameters is preferable to concatenating user-provided values directly into the SQL string.
The asMappedResults() method converts the query results into an array of JavaScript objects.
This creates an object where each item ID maps to an array of matching results.
Grouping results this way can be useful when a script needs to perform repeated lookups without executing another query each time.
What Is the SuiteQL Result Limit?
NetSuite's query.runSuiteQL() method returns a maximum of 5,000 results.
If your query could return more than that, you should use query.runSuiteQLPaged() to retrieve the results in pages.
The paged method also allows you to control how many rows are returned per page.
Running a Paged SuiteQL Query
The query.runSuiteQLPaged() method executes SuiteQL and provides access to the results through a paged data object.
For example:
const sql = `
SELECT
id,
itemid
FROM
item
ORDER BY
id
`;
const pagedResults = query.runSuiteQLPaged({
query: sql,
pageSize: 1000
});
The pageSize property controls the number of results returned per page.
NetSuite supports page sizes from 5 to 1,000 results, with a default of 50.
The ORDER BY clause is important because paged queries should use a unique, unambiguous sort order to avoid duplicate or missing results during pagination.
Iterating Through SuiteQL Result Pages
Unlike an unpaged query, a paged query requires you to retrieve and process each page.
One approach is to use the pageRanges array and fetch() method.
The resulting cache has the same general structure as the unpaged example, but it can process results across multiple pages.
SuiteQL Paged vs. Unpaged Queries
Feature
runSuiteQL()
runSuiteQLPaged()
Result handling
Single result set
Multiple pages
Maximum results
5,000
Higher, subject to account limits
Page size configuration
No
Yes
asMappedResults()
Called on the result set
Called on each fetched page's data
Best use
Smaller queries
Larger result sets
The appropriate method depends on how many records you expect the query to return and how you intend to process them.
SuiteQL Performance Considerations
Pagination helps you retrieve larger result sets, but it doesn't eliminate performance or governance considerations.
Use Filters to Limit Results
Avoid retrieving more records than your script actually needs.
Use appropriate WHERE conditions to reduce the number of returned rows.
Select Only the Required Columns
Instead of using SELECT *, identify the fields your script needs.
This reduces unnecessary data processing.
Use a Consistent Sort Order
Paged queries should use a deterministic ORDER BY clause.
If multiple rows share the same sort value, include another field that makes the ordering unique.
Consider Script Memory Usage
If you're processing a large number of results, storing every row in a JavaScript object can consume significant memory.
For larger workloads, consider processing each page as it is retrieved rather than accumulating the entire result set.
Monitor Governance and Query Limits
Both SuiteQL execution methods consume script governance units.
Paged queries also have result-count and page-count limits, which depend on the account configuration.
For very large datasets, review the relevant NetSuite limits before designing the processing workflow.
Final Thoughts
Use query.runSuiteQL() when your query returns a manageable number of records and you don't need pagination.
When the result set may exceed 5,000 rows, query.runSuiteQLPaged() provides a way to retrieve and process the results across multiple pages.
The main difference is how you access the returned data. With unpaged queries, you can call asMappedResults() directly on the result set. With paged queries, you retrieve each page and call asMappedResults() on that page's data.
For scripts that build lookup caches or process larger datasets, pagination provides greater flexibility while helping you manage the results in smaller batches.
Saving a SuiteQL Query is a built-in feature of Tim Dietrich’s SuiteQL Query Tool. Enabling this functionality requires a few simple customizations: you'll need to create a folder in the File Cabinet and make a minor edit to the SuiteQL Query Tool script. The steps to set this up are outlined below.
Sometimes NetSuite reports, saved searches, and analytics workbooks fall short of providing the data needed for a task. When those native tools hit their limits, it’s time to turn to SuiteQL!
Learn how to use NetSuite SuiteQL to retrieve revenue recognition journal entries by posting period and use the results as input for a SuiteScript Map/Reduce script.
Medical Innovations built the operational foundation to scale without adding headcount—and they're using automation, integrations, and AI to move faster than competitors hundreds of times their size. (Yes, really.)