"type":"error.SuiteScriptError","name":"USER_ERROR","message":"在更改数量之后,您仍需要重新配置库存详细信息记录。" "type":"error.SuiteScriptError","name":"USER_ERROR","message":"You still need to reconfigure the inventory detail record after changing the quantity."
SuiteAnswers ID 81448 的解答:
当系统启用了库存状态功能,访问子记录时会发生已添加行的行为,对新创建的库存详细信息子记录的子列表使用 selectNewLine 方法会返回错误“在更改数量之后,您仍需要重新配置库存详细信息记录” 。如果遇到此问题,建议使用 selectline 方法。
var rec = record.transform({ fromType: 'workorder', fromId: wordOrderId, toType: 'workordercompletion', isDynamic: true, defaultValues: { isbackflush: 'T' } }); // 正文字段赋值 rec.setValue('trandate', new Date()); /** 其他正文字段赋值 **/ // 行字段赋值 var sublistId = 'component'; var lineCounts = rec.getLineCount(sublistId); for (var i = 0; i < lineCounts; i++) { rec.selectLine({ sublistId: sublistId, line: i }); rec.setCurrentSublistValue({ sublistId: sublistId, fieldId: 'quantity', value: lineData[i].qty, }); var subRec = rec.getCurrentSublistSubrecord({ sublistId: sublistId, fieldId: 'componentinventorydetail', }); var detailData = lineData[i].details; var detailSublistId = 'inventoryassignment'; for (var j = 0; j < detailData.length; j++) { // 根据SuiteAnswers的解答,因为启用了库存状态功能,此处需要使用selectLine方法,并非selectNewLine方法 // subRec.selectNewLine({sublistId: detailSublistId}); subRec.selectLine({sublistId: detailSublistId,line:j}); subRec.setCurrentSublistText({ sublistId: detailSublistId, fieldId: 'issueinventorynumber', text: detailData[j].invNum, }); subRec.setCurrentSublistValue({ sublistId: detailSublistId, fieldId: 'binnumber', value: detailData[j].binNum, }); subRec.setCurrentSublistValue({ sublistId: detailSublistId, fieldId: 'inventorystatus', value: detailData[j].status, }); subRec.setCurrentSublistValue({ sublistId: detailSublistId, fieldId: 'quantity', value: detailData[j].quantity, }); subRec.commitLine({ sublistId: detailSublistId }); } rec.commitLine({ sublistId: sublistId }); } rec.save();
另外,根据实际测试,使用标准模式创建完工单也可以避免该报错。
var rec = record.transform({ fromType: 'workorder', fromId: wordOrderId, toType: 'workordercompletion', isDynamic: false, defaultValues: { isbackflush: 'T' } }); // 正文字段赋值 rec.setValue('trandate', new Date()); /** 其他正文字段赋值 **/ // 行字段赋值 var sublistId = 'component'; var lineCounts = rec.getLineCount(sublistId); for (var i = 0; i < lineCounts; i++) { rec.setSublistValue({ sublistId: sublistId, fieldId: 'quantity', value: lineData[i].qty, line: i }); var subRec = rec.getSublistSubrecord({ sublistId: sublistId, fieldId: 'componentinventorydetail', line: i }); var detailData = lineData[i].details; var detailSublistId = 'inventoryassignment'; for (var j = 0; j < detailData.length; j++) { // 标准模式下,给issueinventorynumber赋值时,建议使用setSublistValue方法,而非setSublistText方法 // 原因:当系统中存在不同物料但库存编码相同时,此处可能发生USER_ERROR的错误,此类错误较难排查 subRec.setSublistValue({ sublistId: detailSublistId, fieldId: 'issueinventorynumber', value: detailData[j].invNumId, line: j }); subRec.setSublistValue({ sublistId: detailSublistId, fieldId: 'binnumber', value: detailData[j].binNum, line: j }); subRec.setSublistValue({ sublistId: detailSublistId, fieldId: 'inventorystatus', value: detailData[j].status, line: j }); subRec.setSublistValue({ sublistId: detailSublistId, fieldId: 'quantity', value: detailData[j].quantity, line: j }); } } rec.save();