Started tinkering with running paged queries for t...
# suiteql
s
Started tinkering with running paged queries for the first time but I suspect I'm doing some rookie mistake... not sure why I seem to get data only from the first page
Copy code
function runPaged(q, params) {
    const results = query.runSuiteQLPaged({ query: q, params: params, pageSize: 1000 });
    let output = [];
    for (let page of results.pageRanges) {
        output.push(...results.fetch({ index: page.index }).data.asMappedResults());
    }
    return output;
}
b
code looks fine, check that your query and params are valid
Copy code
require(["N/query"], function (query) {
  const results = query.runSuiteQLPaged({
    query: "select id from transactionline",
    pageSize: 1000,
  });
  let output = [];
  for (let page of results.pageRanges) {
    output.push(...results.fetch(page).data.asMappedResults());
  }
  log.debug('output length', output.length);
});
outputs
message has been deleted
s
Copy code
log.debug('page count', results.pageRanges.length);
 => 47

log.debug('output length', output.length);
 => 1000
😕
Hitting usage limits on simpler queries without params, so must be something about that then... good to know. It was a bit of a "lets see if we can include the kitchensink" experiment.
Copy code
function listRingSerialReport(start, end) {
    const q =
        'SELECT ff.id, ff.trandate, ff.tranid, BUILTIN.DF(line.createdfrom), ' +
        'BUILTIN.DF(line.item), line.quantity, item.description, ' +
        'set.custrecord_gs_ring_serial, set.custrecord_gs_charger_serial ,' +
        'BUILTIN.DF(ff.cseg_gs_country), BUILTIN.DF(customer.category), BUILTIN.DF(line.department) ' +
        'FROM transaction as ff ' +
        'LEFT OUTER JOIN customrecord_gs_ring as set ON ff.id = set.custrecord_gs_ring_createdfrom ' +
        'LEFT OUTER JOIN transactionline as line on ff.id = line.transaction ' +
        'LEFT OUTER JOIN customer on line.entity = customer.id ' +
        'LEFT OUTER JOIN item as item on line.item = item.id ' +
        'WHERE trandate >= ? AND trandate <= ? AND type = ? AND line.quantity > ? ' +
        'AND item.class IN (18, 13, 15) AND customer.category NOT IN (2, 4, 19, 18) ' + // Got tired, do this properly later
        'ORDER BY ff.trandate';

    return query.runPaged(
        q,
        [start, end, DBTYPE, 0]
    );
}
Not expecting help to make that work though ofc, thanks for pointing in the right direction 👍
b
my guess would be the dates
dont know what they are, but you dont have anything that looks like a date related comparison in there
id start with removing the order by clause and then the trandate related conditions
s
Removing the order by did the trick 🙇