I have the following JSON RESTlet script being utilized to export some data. Due to the limitations, it's capped at 1000 lines, which is well under the total that I need to export. I've come across a few different solutions but JSON/RESTlet are fairly new to me so I'm looking for a bit of feedback on how to adjust my code to loop through all the results.
function GetSearchResult(){
//array container for search results
var output = new Array();
//get search results
var results = nlapiSearchRecord('transaction','customsearchid',null,null);
var columns = results[0].getAllColumns();
//loop through the search results
for(var i in results){
//create placeholder object place holder
var obj = new searchRow(
//set the values of the object with the values of the appropriate columns
results[i].getValue(columns[0]),
results[i].getValue(columns[1]),
results[i].getValue(columns[2]),
results[i].getValue(columns[3]),
results[i].getValue(columns[4]),
results[i].getValue(columns[5]),
results[i].getValue(columns[6]),
results[i].getValue(columns[7]),
results[i].getValue(columns[8]),
results[i].getValue(columns[9]),
results[i].getValue(columns[10]),
results[i].getValue(columns[11]),
results[i].getValue(columns[12])
);
//add the object to the array of results
output.push(obj);
}
//return the array of search objects
return output;
}
//Object to serve a place holder for each search row
function searchRow(internalid,lineid,subsidiaryid,locationid,departmentid,accountid,date,name,memo,amount,uniqueid,product,period){
this.internalid = internalid;
this.lineid = lineid;
this.subsidiaryid = subsidiaryid;
this.locationid = locationid;
this.departmentid = departmentid;
this.accountid = accountid;
this.date = date;
this.name = name;
this.memo = memo;
this.amount = amount;
this.uniqueid = uniqueid;
this.product = product;
this.period = period;
}
Here's an example I was trying to follow along with to no avail:
var types = ["Estimate","Opprtnty","SalesOrd","PurchOrd","CustInvc","CashSale"];
var filters = new Array(); //define filters of the search
filters[0] = new nlobjSearchFilter('type',null,'anyof',types);
filters[1] = new nlobjSearchFilter('mainline',null,'is','T');
var columns = new Array();
columns[0] = new nlobjSearchColumn('internalid').setSort(); //include internal id in the returned columns and sort for reference
var results = nlapiSearchRecord('transaction',null,filters,columns); //perform search
var completeResultSet = results; //container of the complete result set
while(results.length == 1000){ //re-run the search if limit has been reached
var lastId = results[999].getValue('internalid'); //note the last record retrieved
filters[2] = new nlobjSearchFilter('internalidnumber',null,'greaterthan',lastId); //create new filter to restrict the next search based on the last record returned
results = nlapiSearchRecord('transaction',null,filters,columns);
completeResultSet = completeResultSet.concat(results); //add the result to the complete result set
}
Thank you for the help!