Skip to content
Advertisement

How to get all items list on NetSuite?

I am just starting with NetSuite and trying to pull all items with details using Restlet. With some research, I am able to pull all the items but the way I am doing now is not straightforward. I first pull the all ids of item using nlapiSearchRecord and loop through each id to get details of each item using nlapiLoadRecord and added to array. This way, it is taking to much time. Is there other way to pull all items with their details? Below is my code.

function getAllIDs() {
    return nlapiSearchRecord('item', null, null, null);
 }

function getRecord() {
    var all_IDs = getAllIDs();
    var len=all_IDs.length;
    var result =new Array();

  for(var i=0;i<all_IDs.length;i++) {
    if(all_IDs[i].getRecordType()==="inventoryitem")
        result[i]=nlapiLoadRecord(all_IDs[i].getRecordType(),all_IDs[i].id)
    }
    return result;
}

Advertisement

Answer

You can use what @Krypton suggested but you will always get 1000 results at max.

Try following if you have requirement to get more than 1000 (using Suitescript 2.0):

    var columns = [];
    var filters = [['isinactive', 'is', 'F']];
    columns.push(search.createColumn({ name: "itemid"}));
    columns.push(search.createColumn({ name: "displayname"}));
    columns.push(search.createColumn({ name: "salesdescription"}));
    columns.push(search.createColumn({ name: "baseprice"}));
    var inventoryitemSearch = search.create({
        type: search.Type.INVENTORY_ITEM, //Change the type as per your requirement
        filters: filters,
        columns: columns
    });
    var arrResults = [];
    var count = 1000;
    var startIndex = 0;
    var endIndex = 1000;
    var resultSet= inventoryitemSearch.run();
    while (count == 1000) {
        var results = resultSet.getRange(startIndex, endIndex);
        arrResults = arrResults.concat(results);
        startIndex = endIndex;
        endIndex += 1000;
        count = results.length;
    }
    log.debug({title: 'arrResults ', details: arrResults });
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement