5

I am trying to implement a search by Category of Inventory Items in Netsuite using their Suitescript API. The following code works as expected so I know I have successful remote communication. But I am stumped as to how to go about searching by Category.

function NSTest() {
    var items = [];

    var filters = [
        //new nlobjSearchFilter('price',null,'lessthan','20'),
        new nlobjSearchFilter('thumbnailurl',null,'isnotempty')
        //new nlobjSearchFilter('internalid',null,'is','60635')
        ];

    var columns = [
        new nlobjSearchColumn('itemid'),
        new nlobjSearchColumn('salesdescription'),
        new nlobjSearchColumn('storedisplaythumbnail'),
        new nlobjSearchColumn('baseprice')
        ];

    var results = nlapiSearchRecord('inventoryitemdetail',null,filters,columns);
    for(var i=0,l=results.length; i < l; i++) { 
        var result = results[i];
        var price   = result.getValue('baseprice');
        var thumbImage  = result.getText('storedisplaythumbnail');
        var desc    = result.getValue('salesdescription');
        var name    = result.getValue('itemid');
        var img   = 'http://shopping.netsuite.com'+thumbImage;
        var item = {desc:desc, price:price, name:name, img:img};
        items.push(item);
    }
    response.write(JSON.stringify(items));
}

This works correctly but if I uncomment the line:

new nlobjSearchFilter('internalid',null,'is','60635')

it does not. Can anyone guide me toward searching items by category in Suitescript?

2 Answers 2

5

Take the quotes off of the internal id number. The search filter for internalid is looking for a number.

5
  • Not true. It actually works both ways. I will give you that it seems to be more efficient if I remove the quotes. I tested it with item internalid's not category id's. Netsuite finally replied and said that they do not support category internalid lookups with the WSDK. And that sucks bigtime. So how do I search by custom field? What I propose to do is introduce a custom field 'catid' in every inventory item record and populate it with its immediate parent category's internalid. But the search is not working. Any ideas? Jul 12, 2012 at 17:56
  • That's odd. I search by internal id all the time, but then again we don't have a webstore, so maybe it's different. You can add a filter for custom fields in the same way as the default fields, just use id of the field: new nlobjSearchFilter('custentity_new_field',null,'is','60635')
    – Corey
    Jul 12, 2012 at 18:33
  • Ok. Explain that. I made a custom field called 'catid'. Its internalid is '52452'. I tried: var filters[0] = new nlobjSearchFilter('catid',null,'is','52452'); nlapiSearchRecord('inventoryitem',null,filters,columns); It didn't work. Jul 12, 2012 at 18:57
  • Ok, catid is your label for you custom field, you need to place the internal id string for that field in the filter. I am assuming this is an entity field, yes? If so go to Setup -> Customization -> Entity Fields and grab the id for the field you created. It will be in the form custentity_catid, if you set the id for it, otherwise it will be like custentity165, or whatever number you are up to in custom fields.
    – Corey
    Jul 12, 2012 at 19:18
  • Mark it answered if it is, pease.
    – Corey
    Jul 12, 2012 at 23:22
0

I checked the record browser and I'm afraid that I couldn't find a valid record internal id 'inventoryitemdetail', you must have mistaken it. It must be 'inventoryitem'. I have checked the code and everything seems working fine.

function start(request, response) {
   var searchId = '27890';
   var filters = new Array();
   filters[0] = new nlobjSearchFilter('internalid', null, 'is',searchId);
   var columns = new Array();
   columns[0] = new nlobjSearchColumn('itemid');
   columns[1] = new nlobjSearchColumn('salesdescription');
   columns[0] = new nlobjSearchColumn('storedisplaythumbnail');
   columns[1] = new nlobjSearchColumn('baseprice');

  // var search = nlapiCreateSearch('customer', filters, columns);
  // var resultSet = search.runSearch();
  // var results = resultSet.getResults(0, 100);
   var results = nlapiSearchRecord('inventoryitem',null,filters,columns);
   var output = "";
   for(var i in results)
       {
            output += results[i].getValue('itemid')+"\n";
            output += results[i].getValue('salesdescription')+"\n";
            output += results[i].getValue('storedisplaythumbnail')+"\n";
            output += results[i].getValue('baseprice')+"\n";

       }
   response.write(output);
}

If it must be inventoryitem then consider the above code.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.