does N/query support limits on returns?
# ask-stanley-ai
e
does N/query support limits on returns?
c
AI generated answer (using internal Slack threads):
Yes, N/query does support limits on returns. However, the limit for a single return is 5000 results. If you need to retrieve more than 5000 results, you can use the
runPaged()
method which allows you to get pages of results that would exceed the normal limit of
query.run()
. The
runPaged()
method has a maximum limit of 1000 results per page. If you need to retrieve a large number of results (e.g., 300k), you can use the ResultSet to get 5000 results at a time and add additional criteria to exclude the previous results in your query. This can be done by treating the internal id as a number and adding a condition to the query. Here is an example of how to use
runPaged()
method:
Copy code
javascript
function getAllQueryResults(rootQuery) {
    var pagedData = rootQuery.runPaged({ pageSize : 1000 });

    var queryData = [];
    for (var i = 0; i < pagedData.pageRanges.length; i++) {
        var currentPage = pagedData.fetch({ index : i });
        var currentPagedData = currentPage.data;
        
        var results = currentPagedData.results;
        for (var j = 0; j < results.length; j++) {
            queryData.push(results[j].asMap());
        }
    }

    return queryData;
}
In this example, the
getAllQueryResults()
function retrieves all the results from a query by running it page by page, with each page containing up to 1000 results. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.839408576
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.834609866
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.826343179
Please provide your feedback on this answer.