首页 > 解决方案 > netsuite suitescript2.0 inventorycount

问题描述

我似乎有点麻烦,我编写了一个应用程序,让我的客户执行库存盘点,但无法使用每个项目的新盘点值更新“inventorycount”记录。

我曾尝试直接更新“countquantity”值,但它忽略了这一点,我现在正在尝试加载“countline”中指定的记录,但这似乎也不起作用。

我的代码如下(用 TypeScript 编写):

/**
 * Update a InventoryCount with a new set of counts
 * @parameters
 * {
 *     service: inventorycount,
 *     method: update,
 *     id: 12345,
 *     inventory: [{
 *         upccode: 98765,
 *         total: 543
 *     }]
 * }
 */
public update() {
    const rec = Record.load({
        type: Record.Type.INVENTORY_COUNT,
        id: this.parameters.id,
        isDynamic: true
    });

    this.parameters.inventory.forEach(item => {
        this.updateLine(rec, item);
    });

    return rec.save();
}

/**
 * Update a single item within the sublist of an inventory count.
 * We update the memo field and the try update the quantity counted.
 *
 * @param rec   the inventorycount record loaded in update
 * @param item  the item object loaded from parameters
 */
private updateLine(rec, item) {
    // fetch the internalid from the upccode
    const internalId = this.upccodeToInternalid(item.upccode);

    // fetch the line number by the given item internal id
    const itemLine = rec.findSublistLineWithValue({
        sublistId: "item",
        fieldId: "item",
        value: internalId
    });

    // select the line to make modifications on
    rec.selectLine({
        sublistId: "item",
        line: itemLine
    });

    // get the current memo so we can append to it
    const currentMemo = rec.getCurrentSublistValue({
        sublistId: "item",
        fieldId: "memo"
    });

    // update the memo field with our new string
    rec.setCurrentSublistValue({
        sublistId: "item",
        fieldId: "memo",
        value: this.mergeMemo(currentMemo, item.areas)
    });

    // get the current item count and append our new count
    const currentQuantity = rec.getCurrentSublistValue({
        sublistId: "item",
        fieldId: "countquantity"
    });

    const newQuantity = currentQuantity + item.total;

    rec.commitLine({sublistId: "item"});
    this.setCount(rec, newQuantity, itemLine);
}

/**
 * Set a new count value for the item provided
 * 
 * @param rec   the inventorycount record containing the item
 * @param value the new value we would like to save for the item count
 * @param iline the sublist item line for the item to be modified
 */
private setCount(rec, value, iline) {
    // select the line to make modifications on
    rec.selectLine({
        sublistId: "item",
        line: iline
    });

    // get the record with the count quantity
    const countId = rec.getCurrentSublistValue({
        sublistId: "item",
        fieldId: "countline"
    });

    this.filters = [];

    this.filters.push(
        Search.createFilter({
            name: "line",
            operator: Search.Operator.EQUALTO,
            values: countId.toString()
        })
    );

    const srch = Search.create({
        type: Search.Type.TRANSACTION,
        filters: this.filters,
        columns: [
            "internalid",
            "quantity",
            "line"
        ]
    });

    let intid;
    srch.run().each(r => {
        intid = r.getValue('internalid');
        return true;
    });

    const crec = Record.load({
        type: Record.Type.INVENTORY_COUNT,
        id: intid,
        isDynamic: false
    });
    crec.setValue('quantity', value);

    return crec.save();
}

任何人都可以更新库存计数状态的奖励业力。

标签: netsuitesublistsuitescript2.0

解决方案


您的代码存在许多问题。

  1. 看起来您正在 update() 方法和 setCount() 方法中加载相同的库存盘点记录。
  2. 如果您计划将此作为一般方法,我怀疑您的条形码到内部 id 方法会占用治理。由于您的代码正在处理单个库存盘点交易,因此您应该在一次搜索中加载和缓存条形码以搜索交易中的所有项目。
  3. 我仍然不明白你从哪里得到countline。这不是 inventorycount 子列表值,除非 2018.2 中有全新的东西

以下示例代码可能会有所帮助。它在控制台窗口中工作。请注意,如果您使用垃圾箱,您还必须确保您拥有正确的垃圾箱和正确的线路。如果您正在使用序列化或批号项目,则需要输入countdetail子记录

require(['N/record'], function(record) {
    var countRec = record.load({
        type: 'inventorycount',
        id: 9946,
        isDynamic: true
    });
    console.log(countRec.getLineCount('item'));
    countRec.selectLine({
        sublistId: 'item',
        line: 0
    });
    console.log(countRec.getSublistValue({
        sublistId: 'item',
        line: 0,
        fieldId: 'countquantity'
    }) + 'in bin: ' + countRec.getCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'binnumber'
    }));
    try {
        var detailRec = countRec.getCurrentSublistSubrecord({
            sublistId: 'item',
            fieldId: 'countdetail'
        }); // only for serialized and lot numbered items
        console.log(JSON.stringify(detailRec));
    } catch (e) {
        console.error(e);
    }
    countRec.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'countquantity',
        value: 44
    });
    countRec.commitLine({
        sublistId: 'item'
    });
    console.log(countRec.save());
}); 

推荐阅读