如何使用SuiteScript采购订单加载项目? [英] How to load items with SuiteScript Purchase Orders?

查看:115
本文介绍了如何使用SuiteScript采购订单加载项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友正在使用NetSuite和SuiteScript.我可以保存运行脚本的采购订单,也可以收取创建的采购订单的费用,但是当我将返回的数据项目值作为空值返回时,我需要获取该项目的ID.

结果给我的NetSuite日志是:

采购订单ID:3706供应商ID:144项目ID:空Tateate:06/08/2015表格:Standard Purchase Order货币:Peso CL

这会发生在所有采购订单上,并且很明显,如果您附加了物料.

加载javascript以使用采购订单"的功能如下:

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;  

}

如果有人可以帮助我.问候!

pd:

我也尝试过:

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

,它不起作用=/

解决方案

答案可能比您期望的要长,但是我们开始吧.

NetSuite将交易记录"(购买订单"是一种交易类型)划分为正文"和订单项"字段.当您进行包含mainline = 'T'的事务搜索时,您在告诉NetSuite仅检索正文"字段数据.但是,item字段是行项目"字段,因此NetSuite不会为其返回任何数据.这就是idItemnull的原因.

了解mainline筛选器的行为对于事务搜索至关重要.基本上是这样的:

  • mainline = 'T'将仅返回正文字段数据,因此每笔交易将仅返回一个搜索结果
  • mainline = 'F'仅返回订单项数据,因此它将为匹配交易的每个订单项返回一个搜索结果
  • 未指定
  • mainline会同时返回正文字段和行数据,因此它将为每个事务本身返回一个结果,再为每个事务中的每一行返回一个结果.

这是一个具体的例子.假设系统中只有一个采购订单与您的所有其他搜索过滤器匹配(mainline除外),并且该采购订单上有三个项目.这是根据mainline过滤器而改变搜索结果的方式:

  • 如果为mainline = 'T',则您将仅获得一个采购订单结果,并且您将仅获得正文"字段中搜索列"的数据.
  • 如果为mainline = 'F',则将得到准确的三个结果,每个订单项一个,并且所有搜索列"将包含数据,无论它们是正文"字段还是行"字段
  • 如果未指定mainline,则将得到准确的四个结果,其中一个仅包含正文"字段的数据,另外三个将同时包含行"和正文"数据

由于我不知道您打算如何使用这些搜索结果,因此很难就应该如何更改搜索提出确切建议.

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 = /

解决方案

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 Transaction
  • mainline = 'F' will only return line item data, so it will return one search result for every line item on matching Transactions
  • mainline 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.

这篇关于如何使用SuiteScript采购订单加载项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆