```2 var results = query.runSuiteQLPaged({ 3 ...
# suitescript
m
Copy code
2		var results = query.runSuiteQLPaged({
3		    query: 'SELECT entityid, email FROM customer',
4		  
5		    pageSize: 10
6		});
7		 
8		results.iterator().each(function(m){
9		  var data = m.value.data.asMappedResults()	
10		})
How does netsuite pagination work. If there are a million records, does it actually return 100,000 pages with 10 results of data per page? It seems like line 9 actually has the data which to me is overkill. Why page over data and return everything other then the result set you actually want (10 customers)?
c
If you have 1,000,005 results and do a paginated search with 10 results per page you'll get 100,000 pages of 10 and then 1 of 5.
m
Wouldnt that only add up to 100,005 results?
c
I missed a 0. should be 100k of 10 and 1 of 5. My bad there.
😀 1
m
So essentially, dont used runPaged but instead implement your own pagination to skip and take as needed.
c
I always use runPaged unless I need 1 result then i just use getRange on the search
i'm garaunteed to get all the results at a slight cost to governance but readability is better IMO
Copy code
const SALES_ORDER_SEARCH = search.create({
            type: search.Type.SALES_ORDER,
            filters: [],
            columns: [
                {name: 'item'}
            ]
        });

        const SALES_ORDER_SEARCH_RESULTS = SALES_ORDER_SEARCH.runPaged({
            pageSize: 1000
        });

        SALES_ORDER_SEARCH_RESULTS.pageRanges.forEach(function(pageRange) {
            SALES_ORDER_SEARCH_RESULTS.fetch({index: pageRange.index}).data.forEach(function(searchResult) {

                const ITEM_ID = searchResult.getValue({name: 'item'});

                if (existingSalesOrderItemIds.indexOf(ITEM_ID) === -1) {
                    existingSalesOrderItemIds.push(ITEM_ID);
                }
            });
        });
m
Ah thats a netsuite search. Im dealing with the query module's runSuiteQLPaged. It only takes in a pageSize param which is weird to me if im running a pagination operation
Meaning i dont have the ability to limit the amount of pages it brings back where as it seems the search module does with getRange
c
according to the doc its almost identical for N/search N/query in terms of paging. Both have the runPaged which returns the same object type that you can iterate over.
Looks like it does just stuff them all in there... weird
m
i wonder if theres a performance concern if there are a million records vs implementing my own pagination (offsetting and limiting based on page and pagesize)
Looks like @tdietrich answered this in a previous post
Copy code
SELECT
	*
FROM
	(
		SELECT
			ROW_NUMBER() 
				OVER ( 
					ORDER BY
						Transaction.ID
				) LineNumber,
			Transaction.ID,	
			Transaction.TranDate,
			Transaction.Type,
			Transaction.TranID
		FROM
			Transaction
		WHERE
			 ( Transaction.Voided = 'F' )
		ORDER BY
			Transaction.ID
	)
WHERE
	LineNumber BETWEEN 5000 and 10000
t
I hope that helped. This goes a little more in depth: https://timdietrich.me/blog/netsuite-suiteql-pagination/
💯 1
m
I thought I can just to runPaged but on 5 million records I only get back 10,000 results worth. I implemented my own pagination referencing your example. Thanks!
303 Views