I have a javascript function to load the list of all that are created Purchase Order, these Purchase Orders are componene Vendor, Items (id item, quiantity item, item amount), Form, Currency, Trandate. When fetching data, it does function properly but gives me more corresponding records, that gives me the result is as follows:
Para Purchase Order: ID Purchase Order: 3505 ID Vendor: Servicio de Impuestos Internos ID Item: UNDEF_MX Trandate: 6/8/2015 Form: Standard Purchase Order Currency: Peso CL
Para Purchase Order: ID Purchase Order: 3505 ID Vendor: ID Item: Donación al Proyecto : itemTest Trandate: 6/8/2015 Form: Standard Purchase Order Currency: Peso CL
Para Purchase Order: ID Purchase Order: 3505 ID Vendor: 1234 ID Item: Trandate: 6/8/2015 Form: Standard Purchase Order Currency: Peso CL
This is seen in the log script NetSuite, for each Purchase Order these three results are seen. I just need you to show me:
Para Purchase Order: ID Purchase Order: 3505 ID Vendor: 1234 ID Item: Trandate: 6/8/2015 Form: Standard Purchase Order Currency: Peso CL
the function code is as follows:
function loadPurchaseOrder(){
nlapiLogExecution('DEBUG','loadPurchaseOrder', 'Entra a funcion loadPurchaseOrder');
var filters = new Array();
filters[0] = new nlobjSearchFilter('purchaseorder',null,'isnotempty');
var columns = new Array();
columns[0] = new nlobjSearchColumn('item');
columns[1] = new nlobjSearchColumn('entity');
columns[2] = new nlobjSearchColumn('trandate');
columns[3] = new nlobjSearchColumn('customform');
columns[4] = new nlobjSearchColumn('currency');
columns[5] = new nlobjSearchColumn('internalid');
var results = nlapiSearchRecord('purchaseorder',null,filters,columns);
var out = "";
for(var i in results){
var purchaseOrder = results[i];
var idPurchaseOrder = purchaseOrder.getText('internalid');
var idVendor = purchaseOrder.getText('entity');
var trandate = purchaseOrder.getValue('trandate');
var form = purchaseOrder.getText('customform');
var currency = purchaseOrder.getText('currency');
var idItem = purchaseOrder.getText('item');
out = " ID Purchase Order: " + idPurchaseOrder + " ID Vendor: " + idVendor + " ID Item: " + idItem
+ " Trandate: " + trandate + " Form: " + form + " Currency: " + currency;
nlapiLogExecution('DEBUG','purchaseOrderCargada', 'Para Purchase Order: ' + out);
}
return out;
}
If anyone can help me please.
PS: the out variable that is returned is only test.
You are probably getting three results because there is one one mainline row and one row for each line item in the purchase order.
The mainline row is the amount for the entire transaction. The line item rows are for each item within that transaction.
You just want the mainline, so you will need to add:
filters.push(new nlobjSearchFilter('mainline', null, 'is', 'T'));