在nlapiSearchRecord列中使用公式

时间:2015-12-31 11:24:07

标签: netsuite suitescript

在脚本中使用adhoc nlapiSearchRecord时,例如:

>

如何在第3列中检索公式的值?

我已尝试 var filters = new Array(); var columns = new Array(); filters[0] = new nlobjSearchFilter('isinactive', null, 'is', 'F' ); filters[1] = new nlobjSearchFilter('vendorcost', null, 'greaterthan', 0); filters[2] = new nlobjSearchFilter('internalid', 'vendor', 'anyof', vendorid ); columns[0] = new nlobjSearchColumn('itemid'); columns[1] = new nlobjSearchColumn('entityid', 'vendor'); columns[2] = new nlobjSearchColumn('vendorcode'); columns[3] = new nlobjSearchColumn('formulanumeric'); columns[3].setFormula('{vendorcost}'); columns[4] = new nlobjSearchColumn('vendorpricecurrency'); columns[5] = new nlobjSearchColumn('isinactive'); columns[6] = new nlobjSearchColumn('vendor'); columns[7] = new nlobjSearchColumn('averagecost'); columns[8] = new nlobjSearchColumn('lastpurchaseprice'); columns[9] = new nlobjSearchColumn('custitem_costrepl'); var searchresults = nlapiSearchRecord('item', null, filters, columns ); searchresults.getValue(column[3])),但都失败了。

原因是,我们的一些searchresults.getValue(3))值是4或5位小数,但普通搜索返回的最小小数精度为3。

2 个答案:

答案 0 :(得分:1)

var filters = new Array();
filters[0] = new nlobjSearchFilter('isinactive', null, 'is', 'F');
filters[1] = new nlobjSearchFilter('vendorcost', null, 'greaterthan', 0);
filters[2] = new nlobjSearchFilter('internalid', 'vendor', 'anyof', vendorid);

var columns = new Array();
columns[0] = new nlobjSearchColumn('itemid');
columns[1] = new nlobjSearchColumn('entityid', 'vendor');
columns[2] = new nlobjSearchColumn('vendorcode');
columns[3] = new nlobjSearchColumn('formulanumeric').setFormula('{vendorcost}'); // you can use formula inline
columns[4] = new nlobjSearchColumn('vendorpricecurrency');
columns[5] = new nlobjSearchColumn('isinactive');
columns[6] = new nlobjSearchColumn('vendor');
columns[7] = new nlobjSearchColumn('averagecost');
columns[8] = new nlobjSearchColumn('lastpurchaseprice');
columns[9] = new nlobjSearchColumn('custitem_costrepl');
var searchresults = nlapiSearchRecord('item', null, filters, columns);

for (var i = 0; searchresults != null && i < searchresults.length; i++) {
    var vendorcost = searchresults[i].getValue(columns[3]);  // gives you the formula field value
}

答案 1 :(得分:1)

你忽略了searchResults是一个数组的事实

有多种方式:

选项#1 //始终有效

searchresults[INDEX].getValue(searchresults[INDEX].getAllColumns()[3]);

选项#2 //始终有效 - 与您尝试的相同,但是,您错过了数组

searchresults[i].getValue(columns[3]);

选项#3 //仅在您有一个数字公式

时使用
searchresults[INDEX].getValue('formulanumeric');