如果在某个字段上勾选了发票,我正在努力从发票创建日记帐分录。这比我习惯的要复杂一点,所以我想寻求一些指导。
我需要做的是: 提交后(){}:
不确定的部分:
getValue 是检索订单项数据的最佳方式吗?此时我有一个可以迭代的对象吗?如何使用 logDebug() 或调试器查看此对象?或者如果有其他方法获取子列表,我如何查看子列表数据?
我真的应该在 beforeSubmit() 上获取发票值,然后使用 afterSubmit() 创建 JE 吗?我可以在 afterSubmit() 函数中使用这些值吗?
拉出线数据和setSublistValue()申请的方法是什么?
如果有人可以在最后一个过程中指导我,那将会有所帮助。
谢谢。
如果您计划只为发票创建 1 个日记帐,我建议您在循环执行 record.create 之前。一切都应该在您的 afterSubmit 中完成。您的 context.newRecord 将拥有您需要的一切。
const journalRec = record.create({type: record.Type.JOURNAL, isDynamic: true});
然后在你的循环中,对于你发票中的每一行,在你打算复制它的时候在你的日志中创建行。你需要你的日记来平衡,所以确保你写在一个循环中,借方和贷方。
for (let i = 0; i < newRecord.getLineCount("item"); i++) {
const amount = newRecord.getSublistValue("item", "amount", i);
log.debug('Amount field', amount) // This will get you the value you retrieved
//Add information to your line
journal.selectNewLine("line");
if (amount > 0) {
journal.setCurrentSublistValue("debit", amount);
} else {
journal.setCurrentSublistValue("credit", amount);
}
//Add Account
//Add another line if you need it to balance
journal.commitLine("line");
}
journal.save();
如果您正在合并发票,您将需要创建一个保存的搜索/查询,并通过 map/reduce 运行它。正如您在提交后提到的 UE,我将假设与您的日记账和发票是一对一的关系。
是的。这就是我认为我需要的。
for(var intLine = 0; intLine < intInvlineCount; intLine ++)
{
//retrieve CMO details from PO, then add as items in Inventory Transfer
var jrnAcct = newInvRec.getSublistValue({
sublistId: 'item',
fieldId: 'account',
line: intLine
});
var jrnMemo = newInvRec.getSublistValue({
sublistId: 'item',
fieldId: 'description',
line: intLine
});
var invAmount = newInvRec.getSublistValue({
sublistId: 'item',
fieldId: 'amount',
line: intLine
});
//addJournal Entry lines
recJournal.selectNewLine({
sublistId: 'line'
});
recJournal.setCurrentSublistValue({
sublistId: 'line',
fieldId: 'account',
value: jrnAcct
});
recJournal.setCurrentSublistValue({
sublistId: 'line',
fieldId: 'debit',
value: invAmount
});
recJournal.setCurrentSublistValue({
sublistId: 'line',
fieldId: 'memo',
value: jrnMemo
});
recJournal.commitLine({
sublistId: 'line'
});
recJournal.selectNewLine({
sublistId: 'line'
});
recJournal.setCurrentSublistValue({
sublistId: 'line',
fieldId: 'account',
value: '872'
});
recJournal.setCurrentSublistValue({
sublistId: 'line',
fieldId: 'credit',
value: invAmount
});
recJournal.setCurrentSublistValue({
sublistId: 'line',
fieldId: 'memo',
value: jrnMemo
});
recJournal.commitLine({
sublistId: 'line'
});
}
现在就像一个魅力!感谢您的输入!