我已经定制了一个现成的脚本来获取批处理到期日期,它在旧记录的编辑模式下工作正常;但在创建模式下会引发错误 这是代码:
/**
* @NApiVersion 2.0
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/record'], function (record) {
function beforeSubmit(context) {
log.debug({details: "beforeSubmit: " + context.type});
var newRecord = context.newRecord;
// Check how many lines exist in the ItemFulfillment - Item sublist.
var lines = newRecord.getLineCount({sublistId: 'item'});
log.debug({details: "lines: " + lines}); // here I am Reading the Sublist Item Lines to Check how many lines there.
if (lines > 0){
for (var x = 0; x < lines; x++){
var lotDetail = "";
var newIventoryDetails = newRecord.getSublistSubrecord({
sublistId: 'item',
fieldId: 'inventorydetail',
line: x
});
var ItemCode = newRecord.getSublistText({
sublistId: 'item',
fieldId: 'itemname',
line: x
});
log.debug({details: "Item Code:" + ItemCode + " Line " + x});
var newInvLines = newIventoryDetails.getLineCount({sublistId: 'inventoryassignment'});
log.debug({details: "Inventory Details Lines = " + newInvLines + " lines"});
if (newInvLines >0 ){
for(z=0; z< newInvLines; z++){
var lotNumber = newIventoryDetails.getSublistText({ // getSublistValue
sublistId: 'inventoryassignment',
fieldId: 'issueinventorynumber',
line: z
});
var lotQty = newIventoryDetails.getSublistText({ // getSublistValue
sublistId: 'inventoryassignment',
fieldId: 'quantity',
line: z
});
var lotExpDate = newIventoryDetails.getSublistText({ // getSublistValue
sublistId: 'inventoryassignment',
fieldId: 'expirationdate',
line: z
});
lotDetail = lotDetail + " lot #: " + lotNumber + " Qty: " + lotQty + " Exp. Date:" + lotExpDate + '\n';
}
}
log.debug({details: lotDetail});
log.debug({Line: x});
newRecord.setSublistText({
sublistId: 'item',
fieldId: 'custcol_inv_full_det',
line: x,
text: lotDetail
});
}
}
}
return {
beforeSubmit: beforeSubmit
};
});
我确信这个错误是因为我正在更新项目列表中的自定义字段,以将文本设置为完整的批处理详细信息(批处理号、数量和到期日期),并且主记录尚未保存或创建。
脚本日志中的错误消息
""Invalid API usage. You must use getSublistValue to return the value set with setSublistValue. ","userEvent":"beforesubmit","stackTrace":["anonymous(N/serverRecordService)","beforeSubmit(/SuiteScripts/inventoryDetails.js:45)"],"notifyOff":false},"id":"","notifyOff":false,"userFacing":false} "
如何在创建模式提交之前更新自定义字段“custcol_inv_full_det”?
最佳答案
您可能需要使用“getSublistValue”而不是“getSublistText”。后者可能不适用于所有值类型。
关于javascript - SuiteScript 2.0 在提交之前更新自定义行字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58951308/