获取Netsuite高级库存序列号的脚本

时间:2013-10-17 05:35:27

标签: inventory netsuite

我正在尝试从使用高级库存的Netsuite帐户中的Fulfillment记录中获取序列号(与Netsuite常规库存系统不同,高级库存将序列号存储在事务记录的子记录中)。我试过使用Netsuite提供的示例,我得到一个NULL响应。我尝试访问现有的已保存搜索,但我得到了错误的字段(保存的搜索在用户界面中工作正常)。有谁知道诀​​窍是什么?这是Netsuite提供的代码示例 -

var ffill=nlapiLoadRecord('itemfulfillment', 5892, {recordmode: 'dynamic'});
ffill.selectLineItem('item', 1);
var invDetailSubrecord = ffill.viewCurrentLineItemSubrecord('item', 'inventorydetail');
invDetailSubrecord.selectLineItem('inventoryassignment', 1);

nlapiLogExecution('DEBUG', 'inventory number: ' + invDetailSubrecord.getCurrentLineItemValue('inventoryassignment', 'receiptinventorynumber'));

使用上面的代码我从Debug语句中得到NULL - “Debug Serial Mgr - Create inventory number = null”

以下是使用现有保存搜索的代码 -

var results = nlapiSearchRecord('itemfulfillment', 620, null, null);
var result = results[0];
var columns = result.getAllColumns();
var columnlen = columns.length;

for (ci = 0; ci < columnLen; ci++)
{
var column = columns[ci];
var label = column.getLabel();
var value = result.getValue(column);
nlapiLogExecution('DEBUG','Serial Mgr', 'Columns ' + label + " " + value);

使用此代码,我从搜索中获得3列但错误的字段(Itemship和553不正确) - “Debug Serial Mgr Columns null 10/16/2013” “Debug Serial Mgr Columns null ItemShip” “Debug Serial Mgr Columns null 553”

2 个答案:

答案 0 :(得分:0)

请尝试以下标签

var label = column.getLabel()||column.getText();

答案 1 :(得分:0)

以下是我如何完成项目实现。这是在预定的脚本中运行的,因为它可能是昂贵的#34;对我们而言,因为我们的客户可能会有非常大的订单履行。

var context = nlapiGetContext();
var internalID = context.getSetting('SCRIPT', 'custscriptitemfulfillment_internalid');
var rec = nlapiLoadRecord("itemfulfillment", internalID);
var count = rec.getLineItemCount("item");
for (var k = 1; k <= count; k++) {
    var internalItemID = rec.getLineItemValue("item", "item", k);
    var itemRecordType = nlapiLookupField('item', internalItemID, 'recordtype');
    if (itemRecordType == 'serializedinventoryitem') {
        var subRec = rec.viewLineItemSubrecord('item', 'inventorydetail', k);
        if (!(!subRec || subRec == null)) {
            var serialNo = [];
            var snc = 0;
            var subRecIntId = subRec.getFieldValue('id');
            var filters = [new nlobjSearchFilter('internalid', null, 'is', subRecIntId)];
            var columns = [
                new nlobjSearchColumn('inventorynumber', 'inventorynumber'),
                new nlobjSearchColumn('quantity'),
                new nlobjSearchColumn('binnumber')
            ];

            var arrSearchResults = nlapiSearchRecord('inventorydetail', null, filters, columns);

            for (var m = 0; m < arrSearchResults.length ; m++) {
                var currSerNo = '';

                var src_serNo = arrSearchResults[m].getValue(columns[0]);
                var src_qty = Math.abs(arrSearchResults[m].getValue(columns[1]));
                var src_bin = arrSearchResults[m].getValue(columns[2]);
                if (src_qty > 0) {
                    if (src_bin && src_bin != null && src_bin > '') {
                        currSerNo = { serialNumber: src_serNo, quantity: src_qty, binNumber: src_bin };
                    }
                    else {
                         currSerNo = { serialNumber: src_serNo, quantity: src_qty };
                    }
                    serialNo[snc] = currSerNo;
                    snc++;
                }
            }
            // snc has a count of all the serial numbers on that fulfilled item
            // serialNo is an array with the serialized items, including their location and bin when applicable.
            // These two get reset on the next line item so process them now.
        }
    }
}

任何错误都是由于重命名的变量和减少代码以删除其他功能所致。