Eng
This error pops up when you are creating an item receipt record from a purchase order and trying to set different item id to a item sublist line.
Let me explain it with an example:
Purchase order JNPO#0001 has been created as below
line | item ID | quantity | rate |
0 | 1000 | 10 | $5.00 |
1 | 1001 | 10 | $6.00 |
Let’s create an item receipt from it using SuiteScript
let irRec = record.transform({fromType: 'purchaseorder', toType:'itemreceipt', fromId: '100001'});//open the record
irRec.selectLine({sublistId: 'item', line: 0});//select first line on the receipt
irRec.setCurrentSublistValue({sublistId: 'item', fieldId: 'itemreceive', value: true});//tick received box
irRec.setCurrentSublistValue({sublistId: 'item', fieldId: 'item', value: '1001'});//set item to 1001 but actually the item on the line is 1000
irRec.commitLine({sublistId: 'item'});//you wont see the error here
let irId = irRec.save();//boom
In this example, on the item receipt the code is trying to modify the line item, while the item can only be ticked if the item is received and the quantity can be updated to record the actual received quantity. Setting item id to a line where the item id is the same won’t cause the error.
To prevent this error from happening, first thing is to check the item id with your input if you are locating lines with line id. If line item id is not what’s in your payload then populate an custom error saying “hey line 1 is item A but you give me item B”.
中文
这个错误的原因是在创建Item Receipt的时候,你尝试在某一行给item赋一个不一样的值。
举例子说一下
行号 | 货品id | 数量 | 单价 |
0 | 1000 | 10 | $5.00 |
1 | 1001 | 10 | $6.00 |
对于这个订单你这样操作一下
let irRec = record.transform({fromType: 'purchaseorder', toType:'itemreceipt', fromId: '100001'});//open the record
irRec.selectLine({sublistId: 'item', line: 0});//select first line on the receipt
irRec.setCurrentSublistValue({sublistId: 'item', fieldId: 'itemreceive', value: true});//tick received box
irRec.setCurrentSublistValue({sublistId: 'item', fieldId: 'item', value: '1001'});//set item to 1001 but actually the item on the line is 1000
irRec.commitLine({sublistId: 'item'});//you wont see the error here
let irId = irRec.save();//boom
这个例子尝试用代码更改货品的id,而对于收货单你只能打勾来表示收货,或者是更改数量表示你收货多少。但是如果你给货品赋值是一样的id,就不会报错。
为了防止这样的bug,如果你用行号定位收货单上的货品,最好和你输入对比一下货品的id,如果不一致就报错,避免张冠李戴。
最后送上一个遇到这个bug我下意识想到的电影片段:D
This bug reminds me of a Stephen Chow’s movie 😀
Comments