如何在Netsuite的Suitescript中按内部ID搜索记录?

时间:2012-07-11 13:21:12

标签: netsuite

我正在尝试使用他们的Suitescript API在Netsuite中按库存项目类别进行搜索。以下代码按预期工作,因此我知道我已成功进行远程通信。但我很难过如何按类别进行搜索。

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

这可以正常工作,但如果我取消注释该行:

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

它没有。 任何人都可以指导我在Suitescript中按类别搜索项目吗?

2 个答案:

答案 0 :(得分:4)

从内部ID号中取出引号。 internalid的搜索过滤器正在寻找一个数字。

答案 1 :(得分:0)

我检查了记录浏览器,我担心我找不到有效的记录内部ID&#39; inventoryitemdetail&#39;,你一定是弄错了。它必须是“库存品”&#39;。我检查了代码,一切似乎都正常。

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

如果必须是inventoryitem,请考虑以上代码。