我似乎有点不高兴,我写了一个应用程序,让我的客户执行库存盘点,但无法用每个项目的新盘点值更新“库存盘点”记录。
我尝试直接更新'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();
}
任何人也可以更新库存计数状态的奖励业力。
答案 0 :(得分:0)
您的代码有很多问题。
下面的示例代码可能会有所帮助。它在控制台窗口中工作。请注意,如果您使用的是垃圾箱,则还必须确保您拥有正确的垃圾箱以及正确的行。如果您要处理序列化或批号项目,则需要输入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());
});