Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124

需求: 在Business Central 的Report程式中, 如何利用銀行代號(Bank Account No.)取得銀行名稱, 利用客戶編號(Bal. Account No.)取得客戶名稱
在 Business Central 的 Report(AL) 中,要:
做法都是:用對應的 Master Table(Bank Account / Customer)去 Get 該筆 Record
Name範例程式碼(Report)
var
BankAccount: Record "Bank Account";
BankName: Text[100];
begin
BankName := '';
if BankAccount.Get("Bank Account No.") then
BankName := BankAccount.Name;
end;OnAfterGetRecord()OnPreReport()trigger 中注意:Bal. Account No. 只是編號,必須搭配 Bal. Account Type 才知道它是「客戶 / 廠商 / G/L」。
程式範例(同時支援 Customer / Vendor / G/L):
var
Customer: Record Customer;
Vendor: Record Vendor;
GLAccount: Record "G/L Account";
BalAccountName: Text[100];
begin
BalAccountName := '';
case "Bal. Account Type" of
"Bal. Account Type"::Customer:
if Customer.Get("Bal. Account No.") then
BalAccountName := Customer.Name;
"Bal. Account Type"::Vendor:
if Vendor.Get("Bal. Account No.") then
BalAccountName := Vendor.Name;
"Bal. Account Type"::"G/L Account":
if GLAccount.Get("Bal. Account No.") then
BalAccountName := GLAccount.Name;
end;
end;report 60232 "Check Ledger Entries List"
{
Caption = 'Check Ledger Entries Report'; // 應收票據帳本分錄清單
UsageCategory = ReportsAndAnalysis;
ApplicationArea = All;
DefaultLayout = RDLC;
RDLCLayout = 'CheckLedgerEntriesList.rdl'; // 報表的檔案名稱
// 報表的主要資料集
dataset
{
// 報表的主資料項 (Data Item) 應收票據帳本分錄資料表
dataitem(CheckLedgerEntries; "Check Ledger Entry")
{
// 設定篩選條件 (如果需要,可以在這裡加入過濾器)
RequestFilterFields =
"Document No.",
"Entry No.",
"Bank Account No.",
"Posting Date",
"Bal. Account No.";
// 排序設定
DataItemTableView = sorting("Document No.", "Entry No.");
// 定義要在報表中顯示的欄位
column(CustomerNo; "Bal. Account No.")
{
Caption = '客戶編號';
}
column(BankAccountNo; "Bank Account No.")
{
Caption = '銀行代號';
}
column(BankAccountType; "Bal. Account Type")
{
Caption = '銀行類型';
}
// ===== 新增:名稱欄位(綁定變數)=====
column(BankAccountName; BankAccountNameTxt)
{
Caption = '銀行名稱';
}
column(CustomerName; CustomerNameTxt)
{
Caption = '客戶名稱';
}
trigger OnAfterGetRecord()
begin
// 預設清空
BankAccountNameTxt := '';
CustomerNameTxt := '';
// 1️⃣ 由 Bank Account No. 取得銀行名稱
if ("Bank Account No." <> '') then
if BankAccount.Get("Bank Account No.") then
BankAccountNameTxt := BankAccount.Name;
// 2️⃣ 由 Bal. Account No. 取得客戶名稱(一定要判斷 Type)
if ("Bal. Account Type" = "Bal. Account Type"::Customer) and
("Bal. Account No." <> '') then
if Customer.Get("Bal. Account No.") then
CustomerNameTxt := Customer.Name;
end;
}
}
// ===== 全域變數 =====
var
BankAccount: Record "Bank Account";
Customer: Record Customer;
BankAccountNameTxt: Text[100];
CustomerNameTxt: Text[100];
}