我已创建摊销计划日记账分录。需要获取时间表编号。行级字段。我在提交脚本之前创建了用户事件。我能够获取部门、描述、时间表编号。编辑模式下的字段值。创建模式下的部门和描述。但在附表编号中获得空白值。字段日志即使在创建模式下也有价值。如何获取这个值?
/**
define(['N/记录', 'N/ui/serverWidget', 'N/搜索', 'N/ui/消息', 'N/运行时'],
function (record, serverWidget, search, message, runtime) {
function beforeSubmit(context) {
// try {
var rec = context.newRecord;
var recType = rec.type;
log.debug("recType",recType);
//Journal Entry
if (recType === 'journalentry') {
log.debug("context",context.type);
if (context.type === 'create') {
log.debug("creating......");
var numLines = rec.getLineCount({
sublistId: 'line'
});
log.debug("numLines", numLines);
for(var s=0;s<numLines;s++)
{
var scheduleNo = rec.getSublistValue({
sublistId: 'line',
fieldId: 'schedulenum',
line: s
});
log.debug("scheduleNo", scheduleNo);
var department = rec.getSublistValue({
sublistId: 'line',
fieldId: 'department',
line: s
});
log.debug("department", department);
var decs = rec.getSublistValue({
sublistId: 'line',
fieldId: 'memo',
line: s
});
log.debug("decs", decs);
}
}
}
}
return {
beforeSubmit: beforeSubmit
}
});
我可以使用下面的代码在创建模式下获取 Schedule num 的值
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
define(['N/record', 'N/log'], function(record, log) {
const beforeSubmit = (context) => {
try {
// Ensure the script runs only on create
if (context.type !== context.UserEventType.CREATE) {
return;
}
const { newRecord } = context;
// Get the number of lines
let lineCount = newRecord.getLineCount({ sublistId: 'line' });
for (let i = 0; i < lineCount; i++) {
const scheduleNo= newRecord.getSublistValue({
sublistId: 'line',
fieldId: 'schedulenum',
line: i
});
log.debug('schedule num', scheduleNo);
}
} catch (e) {
log.error({
title: e.name,
details: e.message
});
}
};
return {
beforeSubmit: beforeSubmit
};
});