解决Posted Transfer Receipts页面扩展无法汇总Item Ledger Entry字段值问题
问题排查与修正方案
可能的问题原因
- 过滤条件缺失关键维度:仅通过
Document No.过滤Item Ledger Entry表并不足够,同一单据号可能对应不同文档类型(如Transfer Receipt、Transfer Shipment等),需要额外过滤Document Type为Transfer Receipt才能精准匹配目标条目。 - 不必要的
>0过滤限制:Transfer Receipt对应的Cost Amount (Actual)可能存在负数场景(如退货调整),该过滤会排除部分有效金额,导致总和与预期不符。 - 低效的循环累加逻辑:手动循环累加易因逻辑疏漏出错,且性能不如Business Central内置的
CalcSum方法可靠。 - 字段显示属性缺失:未配置金额格式化属性,可能导致数值显示异常(看起来为空)。
修正后的代码
{ layout { addafter("Posting Date") { field(GrandTotalAmount; GrandTotalAmount) { ApplicationArea = All; Caption = 'Grand Total Amount'; AutoFormatType = 1; // 自动适配金额显示格式 Editable = false; } } } trigger OnAfterGetRecord() var ItemLedgEntry: Record "Item Ledger Entry"; begin GrandTotalAmount := 0; // 精准匹配Posted Transfer Receipt对应的条目 ItemLedgEntry.SetRange("Document Type", ItemLedgEntry."Document Type"::"Transfer Receipt"); ItemLedgEntry.SetRange("Document No.", Rec."No."); // 使用内置CalcSum方法直接计算总和,高效可靠 ItemLedgEntry.CalcSum("Cost Amount (Actual)"); GrandTotalAmount := ItemLedgEntry."Cost Amount (Actual)"; end; var GrandTotalAmount: Decimal; }
额外验证建议
- 查看
Item Ledger Entry表中对应单据号的记录,确认Document Type是否为Transfer Receipt,以及Cost Amount (Actual)的数值是否符合预期。 - 测试包含负数金额的场景,验证总和是否正确累加正负数值。
内容的提问来源于stack exchange,提问作者Codinger
相关产品推荐
相关产品推荐

