简体   繁体   English

netsuite suitescript2.0库存计数

[英]netsuite suitescript2.0 inventorycount

I seem to be in a bit of a pickle, I have written an app that lets my client perform an inventory count but am unable to to update the 'inventorycount' record with the new count values for each item. 我似乎有点不高兴,我写了一个应用程序,让我的客户执行库存盘点,但无法用每个项目的新盘点值更新“库存盘点”记录。

I have tried updating the 'countquantity' value directly but it ignores this, I am now trying to load the record specified in 'countline', but this doesn't seem to be working either. 我曾尝试直接更新'countquantity'值,但是它忽略了这一点,我现在正尝试加载'countline'中指定的记录,但这似乎也不起作用。

My code is as follows (written in TypeScript): 我的代码如下(用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();
}

Bonus karma for anyone who can also update the inventorycount status. 对于任何还可以更新库存计数状态的人,均可获得奖励业力。

There are a number of issues with your code. 您的代码有很多问题。

  1. It looks like you are loading the same inventory count record in the update() method and in the setCount() method. 看来您正在update()方法和setCount()方法中加载相同的库存盘点记录。
  2. If you are planning this as a general method I have a suspicion that your barcode to internal id method is going to eat up governance. 如果您打算将其作为一种通用方法,我怀疑您的条形码到内部ID的方法将吞噬治理。 Since your code is working on a single Inventory Count transaction you should load and cache the barcodes in a single search for all items on the transactions. 由于您的代码正在处理单个“库存盘点”交易,因此您应在一次搜索中加载和缓存条形码,以查找交易中的所有项目。
  3. I still don't understand where you are getting countline from. 我仍然不明白你从哪里得到计数线。 This is not an inventorycount sublist value unless something completely new is in 2018.2 除非2018.2中有全新的内容,否则这不是库存计数子列表值。

The following bit of sample code may help. 下面的示例代码可能会有所帮助。 It works in a console window. 它在控制台窗口中工作。 Note if you are using bins you'll also have to make sure you have the correct bin as well as the correct line. 请注意,如果您使用的是垃圾箱,则还必须确保您拥有正确的垃圾箱以及正确的行。 If you are working with serialized or lot numbered items you'll need to enter countdetail subrecords 如果您使用序列化或批号项目,则需要输入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());
}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM