netsuitepurchase-ordersuitescript

How to load items with SuiteScript Purchase Orders?


Friends'm working with NetSuite and SuiteScript. I can save a purchase order running the script and also charge Purchase Orders created, but when I bring returns data item value as a null value, and I need to get the id of the item.

The result gives me the log NetSuite is:

Purchase Order ID: 3706 Vendor ID: 144 Item ID: null Trandate: 06/08/2015 Form: Standard Purchase Order Currency: Peso CL

this happens all Purchase Orders and obviously if you have an item attached.

function to load javascript to use Purchase Order is as follows:

function loadPurchaseOrder(){

nlapiLogExecution('DEBUG','loadPurchaseOrder', 'Entra a funcion loadPurchaseOrder');    

//se aplican filtros para la busqueda del objeto  
var filters= new Array();
filters[0] = new nlobjSearchFilter('purchaseorder',null,'isnotempty');
filters[1] = new nlobjSearchFilter('mainline', null, 'is', 'T');

//seleccion de los campos que se quieren extraer
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 = "";
if(results != null ){

    for(var i=0; i< results.length; i++){

        var purchaseOrder = results[i];
        var idItem = purchaseOrder.getValue('item');                        
        var idVendor = purchaseOrder.getValue('entity');
        var trandate = purchaseOrder.getValue('trandate');
        var form = purchaseOrder.getText('customform');
        var currency = purchaseOrder.getText('currency');
        var idPurchaseOrder = purchaseOrder.getText('internalid');

        out = " ID Purchase Order: " + idPurchaseOrder + " ID Vendor: " + idVendor + " ID Item: " + idItem
              + " Trandate: " + trandate + " Form: " + form + " Currency: " + currency;

        nlapiLogExecution('DEBUG','purchaseOrderCargada', out);

    }
} 

return out;  

}

If someone could please help me. Greetings!

pd:

I've also tried:

var idItem = nlapiGetLineItemField ('item', 'item');

and it does not work = /


Solution

  • This is maybe a longer answer than you're expecting, but here we go.

    NetSuite divides Transaction records (Purchase Order is a type of Transaction) into Body and Line Item fields. When you do a Transaction search that includes mainline = 'T', you are telling NetSuite to only retrieve Body field data. The item field, however, is a Line Item field, so NetSuite will not return any data for it. That's why idItem is null.

    Understanding the behaviour of the mainline filter is crucial to Transaction searches. Basically, it goes like this:

    Here's a concrete example. Let's say that there is only one Purchase Order in the system that matches all of your other search filters (besides mainline), and that Purchase Order has three items on it. This is how the search results will change based on the mainline filter:

    It's difficult to advise on exactly how you should change your search as I do not know what you plan to do with these search results.