我嘗試根據記錄類型和索引獲取記錄。Netsuite API花費很長時間迴應
請求: { 「記錄類型」: 「客戶」, 「gu_action」: 「get_all」, 「大小」:1000, 「指數」:0}
其正常工作。但Api會每4-6小時響應每個API調用。任何想法如何減少這個時間?
我的Restlet代碼:
get_all行動將調用get_Allrecords功能:
/********************** Get All records of Record type *******************************/
function get_Allrecords(datain) {
var all_IDs = getAllIDs(datain);
var len = all_IDs.length;
var result = new Array();
var results = new Array();
var fields = datain.fields;
for (var i = 0; i < len; i++) {
var required_result = {};
try {
result[i] = **nlapiLoadRecord(all_IDs[i].getRecordType(), all_IDs[i].id);**
if(fields != undefined && fields.length > 0) {
for(var j = 0; j<fields.length; j++){
req = fields[j];
if(result[i].getFieldValue(req) != undefined){
required_result[req] = result[i].getFieldValue(req);
}
if(req == "recordtype"){
required_result[req] = all_IDs[i].getRecordType();
}
}
} else {
required_result =result[i];
}
} catch (ex) {
if (ex.code == "INSUFFICIENT_PERMISSION") {
}
} //try.... catch... ends
results.push(required_result);
} //for ends
return results;
}
/回撥get_All記錄/
function getAllIDs(datain) {
var MAX_SIZE = typeof(datain.size) == 'undefined' ? 200 : datain.size;
var INDEX = 0;
if (typeof(datain.index) !== 'undefined') {
INDEX = datain.index * MAX_SIZE;
MAX_SIZE += INDEX;
}
/*** Define search filters ***/
var NS_filters = new Array();
var columns = new Array();
columns[0] = new nlobjSearchColumn('lastmodifieddate').setSort(1);
var search = **nlapiCreateSearch(datain.recordtype, NS_filters, columns)**
var results = search.runSearch();
var records = results.getResults(INDEX, MAX_SIZE);
return records;
}
謝謝@erictgrubaugh – Saravanakumar