William Rodriguez
01/02/2024, 2:37 PMerictgrubaugh
01/02/2024, 2:55 PMrunPaged()
and fetch()
methods each use 5 units. currentPage.data
is just a standard JS Array; the JS forEach
method is not going to consume any governance.alien4u
01/02/2024, 3:30 PMrunPaged({pageSize: 1000})
If you don't use pageSize
with the max value, your search could run out of governance with a very large search because it will use the default pageSize(~100).William Rodriguez
01/02/2024, 3:31 PMWilliam Rodriguez
01/02/2024, 3:34 PMTimothy Wong
01/03/2024, 3:12 PMrequire(['N/runtime', 'N/search'], function (runtime, search) {
try {
var searchObj = search.create({
type: "transaction",
filters:
[
["mainline", "is", "T"]
],
columns:
[
search.createColumn({
name: "ordertype",
sort: search.Sort.ASC
}),
"mainline",
"trandate",
"asofdate",
"postingperiod",
"taxperiod",
"type",
"tranid",
"entity",
"account",
"memo",
"amount",
]
});
var searchResultCount = searchObj.runPaged().count;
log.debug("searchObj result count", searchResultCount);
var list = [];
var page;
var pagedData;
pagedData = searchObj.runPaged({ pageSize: 1000 });
pagedData.pageRanges.forEach(function (pageRange) {
page = pagedData.fetch({ index: pageRange.index });
page.data.forEach(function (row) {
//log remaining usage
return true;
});
log.debug('remaining usage after fetch' + pageRange.index, runtime.getCurrentScript().getRemainingUsage());
return true;
});
log.debug('remaining usage at end', runtime.getCurrentScript().getRemainingUsage());
} catch (e) {
var scriptId = runtime.getCurrentScript().id;
log.error('ERROR:' + scriptId + ':fn:' + runtime.executionContext, JSON.stringify({ type: e.type, name: e.name, message: e.message, stack: e.stack, cause: JSON.stringify(e.cause), id: e.id }));
}
});