Hi, I'm trying to speed up an existing 1.0 script...
# suitescript
w
Hi, I'm trying to speed up an existing 1.0 script and need to search for all posting transaction lines in a fiscal year and gather around 20 columns of data for them. At the moment the process is the following: 1. load search 2. run search 3. get result(0,1000) <-- first run takes ~70s 4. extract all data from the result 5. load search 6. add filter to filter out all lines that have been processed 7. run search 8. get result(0,1000) ... repeat <-- is a tiny bit faster then previous One idea I have is to first run a search for only the internalID's and then run a search for each transaction. This would probably speed up the individual transaction searches but would increase the amount of searches needed as short transactions also requires a search. (albeit faster?). Maybe count the number of lines in the initial search and allow several transactions as long as the result is within 1000 lines? Any tips? Currently the account has around 2 million lines that needs to be extracted. Here's the grunt of the search:
Copy code
var search = nlapiCreateSearch("transaction",
[
   ["account.type","anyof","FixedAsset","Bank","Equity","DeferRevenue","DeferExpense","Income","Expense","COGS","CredCard","AcctRec","AcctPay","LongTermLiab","UnbilledRec","OthAsset","OthExpense","OthIncome","OthCurrLiab","OthCurrAsset"], 
   "AND", 
   ["posting","is","T"], 
   "AND", 
   ["amount","notequalto","0.00"], 
   "AND", 
   ["postingperiod","rel","TFY"],
   "AND", 
   ["formulanumeric: TO_NUMBER({internalid}||'.'||lpad({linesequencenumber},4,'0'))","greaterthan","17349.0125"]
], 
[
   new nlobjSearchColumn("type"), 
   new nlobjSearchColumn("formulatext").setFormula("to_char({trandate}, 'YYYYMMDD')"), 
   new nlobjSearchColumn("formulatext").setFormula("to_char({datecreated}, 'YYYYMMDD')"), 
   new nlobjSearchColumn("createdby"), 
   new nlobjSearchColumn("number","account",null), 
   new nlobjSearchColumn("type","account",null),
   new nlobjSearchColumn("internalid","class",null), 
   new nlobjSearchColumn("internalid","department",null), 
   new nlobjSearchColumn("internalid","location",null), 
   new nlobjSearchColumn("signedamount"), 
   new nlobjSearchColumn("internalid").setSort(false), 
   new nlobjSearchColumn("line"), 
   new nlobjSearchColumn("mainline"), 
   new nlobjSearchColumn("taxline"), 
   new nlobjSearchColumn("tranid"), 
   new nlobjSearchColumn("trandate"), 
   new nlobjSearchColumn("linesequencenumber").setSort(false),
   new nlobjSearchColumn("formulanumeric").setFormula("TO_NUMBER({internalid}||'.'||lpad({linesequencenumber},4,'0'))")
]
);


var t1 = performance.now();
srs = search.runSearch();
console.log('time to run search: '+((performance.now()-t1)/1000)+'s')

var t1 = performance.now();
var result = srs.getResults(0,1000);
console.log('time to load result: '+((performance.now()-t1)/1000)+'s')