2017-04-20 4 views
1

私は以下のJSON RESTletスクリプトを使ってデータをエクスポートしています。制限のため、1000行に制限されています。これは、エクスポートする必要がある総量のかなり下です。私はいくつかの異なるソリューションに出くわしましたが、JSON/RESTletはかなり新しいものです。すべての結果をループするようにコードを調整する方法のフィードバックを探しています。NetSuite RESTlet保存済み検索の返品制限

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; 

} 

ここでの例では、私は無駄にして一緒に従うしようとしていたのです。

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 
} 

が助けてくれてありがとう!

答えて

2

Netsuite Saved Searchを読み込み、その結果を標準のJavascriptオブジェクトの配列として取り出すことができ、1000個の結果の上限に制限されない汎用関数です。

function getSearchResults(id) { 
    var search = nlapiLoadSearch(null, id); 
    var columns = search.getColumns(); 
    var resultSet = search.runSearch(); 

    var results = []; 
    var slice = []; 
    var i = 0; 

    do { 
    slice = resultSet.getResults(i, i + 1000); 
    slice.forEach(function(result) { 
     var resultObj = {}; 
     columns.forEach(function(column) { 
     resultObj[column.getName()] = result.getValue(column); 
     }); 
     results.push(resultObj); 
     i++; 
    }); 
    } while (slice.length >= 1000); 

    return results; 
} 
+0

このコードを使用して、nlapiLoadSearchの下でレポートIDを使用しようとすると、タイムアウトエラーが発生します。それを運転するのは何ですか? – Ryan

+0

UIの結果はいくつですか? – michoel

+0

通常15〜20Kの結果があります – Ryan

関連する問題