Saravanakumar
Saravanakumar

Reputation: 45

Netsuite API Taking long time to response

i try to getting records based on recordtype and index.

Request: {"recordtype":"customer","gu_action":"get_all","size":1000,"index":0}

Its Works fine. But Api taking 4-5 minitues to response for every api call. Any idea how to reduce this time?

My Restlet Code:

get_all action will call the get_Allrecords function:

/********************** 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;
}

/Call back of get_All Records/

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;
}

Upvotes: 2

Views: 2137

Answers (1)

erictgrubaugh
erictgrubaugh

Reputation: 8847

The nlapiLoadRecord call in get_Allrecords is your performance bottleneck. Loading an entire record from the database is one of the most expensive operations in SuiteScript -- especially if the records are Transactions -- and you're loading 1000 records in your request.

Loading the heavier records (i.e. Transactions) in NetSuite can take a couple seconds, so 1,000 records taking several minutes is not surprising.

Do you really need all of the fields on every record? You would get much better performance from a single Search that only contains the columns you want for each record, rather than trying to load every full record.

If you do need all of the fields on every record, you may need to look into the SuiteTalk SOAP API instead; while it has much slower performance in general than RESTlets, it can outperform RESTlets on very large requests like this one.

Upvotes: 5

Related Questions