Anybody know the best way to page results when run...
# suitescript
n
Anybody know the best way to page results when running a query? It stops at 5000 and i need to get them all. Currently doing this.
Copy code
let queryResults = query.runSuiteQL({
        query: sqlStatement
      });

      let results = queryResults.asMappedResults();
b
the standard way is you run a paged query
n
Awesome, thanks. Is the results output the same or do you have to handle that differently for paged vs mappedResults?
@battk
b
slightly different, you eventually get an array of query results that you have to individually use asMap
n
Okay, cool ill work with it. THanks!
b
if you really wanted to keep the output the same, you can modify the query to do your own pagination using rownum
and then just call runSuiteQL a bunch of times with slightly different queries
n
sweet, thanks for the help. I'll check out these resources. Found the Tim rownum thing but hadn't had a chance to fully dive into it.
@battk sadly the paged options i tried just kept timing out with script execution exceeded. So, gonna try the row number thing and may have to run it in groups.
@battk Alright thought i would share since i got it working. So, I have a async await function that runs two queries (one which returns row numbers 1-4000 and the second returns 4000-6000). Then i combine those mappedResults before returning the full array of in my case 5100 results. Works perfect.
Copy code
async function getSQLData() {
let sqlStatement = getSql(row, col, wk, yr, 'first');
        let sqlStatementTwo = getSql(row, col, wk, yr, 'second');

        let queryResults = query.runSuiteQL({
          query: sqlStatement
        });

        let queryResultsTwo = query.runSuiteQL({
          query: sqlStatementTwo
        });

        let results = await queryResults.asMappedResults();
        await results.push(...(await queryResultsTwo.asMappedResults()));

          return {data: results, wk: wk, yr: yr, row: row, col: col};
        }