I'm writing a restlet that will return all Bill, Credit Card, and Journal transactions within a NetSuite account (see code below). My issue is that given the volume of data (100k+ transaction records), I'm getting a timeout error. Is there any way for me to optimize my code to avoid this timeout error? Is there a way for me to pass the restlet parameters around the PageRanges and just make multiple calls?
/**
*@NApiVersion 2.x
*@NScriptType Restlet
*/
define(['N/error', 'N/search'],
function(error, search) {
function doValidation(args, argNames, methodName) {
for (var i = 0; i < args.length; i++)
if (!args[i] && args[i] !== 0)
throw error.create({
name: 'MISSING_REQ_ARG',
message: 'Missing a required argument: [' + argNames[i] + '] for method: ' + methodName
});
}
function _get(context) {
doValidation('GET');
var mySearch = search.create({
type: search.Type.TRANSACTION,
columns: ['account', 'recordtype','trandate', 'tranid', 'memo', 'amount', 'department', 'entity' ],
filters: [['recordtype', 'is', 'vendorbill'], 'or', ['recordtype', 'is', 'creditcardcharge'],'or', ['recordtype', 'is', 'journalentry']]
});
results = []
var myPagedData = mySearch.runPaged({
pageSize: 1000
})
myPagedData.pageRanges.forEach(function(pageRange){
var myPage = myPagedData.fetch({index: pageRange.index})
results.push(myPage.data)
})
return results
}
return {
get: _get,
};
});
You can refresh the restLet for time exceed error as it has 5 minute(300 seconds) time limit only. you can use N/runtime moduleto get its governance limit and N/cache module to store the already done data. check the remaining governance and curren t time in loop. and break the loop and call again restLet after storing already done data using cache module. Pass remaining data as a parameter while calling.