问题
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 = /
回答1:
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:
mainline = 'T'
will only return body field data, so it will return exactly one search result per Transactionmainline = 'F'
will only return line item data, so it will return one search result for every line item on matching Transactionsmainline
not specified will return both body field and line data, so it will return one result for each transaction itself plus one result for each line on each transaction.
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:
- If
mainline = 'T'
then you will get exactly one result for the Purchase Order, and you will only get data for Search Columns that are Body fields. - If
mainline = 'F'
then you will get exactly three results, one for each line item, and all of your Search Columns will contain data whether they are Body or Line fields - If
mainline
is not specified then you will get exactly four results, one of them will only contain data for Body fields, and the other three will contain both Line and Body data
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.
来源:https://stackoverflow.com/questions/31929239/how-to-load-items-with-suitescript-purchase-orders