web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Unanswered

I wanted to copy data from bank account ledger entry to a custom table on basis of entry no via job queue,if entry no does exist already in custom table then,statement no,statement status were updated only.I have written code for it.is it correct?

(0) ShareShare
ReportReport
Posted on by 236
I wanted to copy data from bank account ledger entry to a custom table on basis of entry no via job queue,if entry no does exist already in custom table then,statement no,statement status were updated only.I have written code for it.is it correct?
codeunit 90127 BankAccountLedgerEntryCustom
{
    VAR
        SourceTableVar: Record "Bank Account Ledger Entry";
        DestinationTableVar: Record BALTable;
       

    trigger OnRun()
    BEGIN

        SourceTableVar.RESET;
        SourceTableVar.SetRange("Entry No.");
        SourceTableVar.FindLast();
       
        DestinationTableVar.SetRange("Entry No.", SourceTableVar."Entry No.");
       
        IF not
        DestinationTableVar.FINDSET() THEN BEGIN
            REPEAT
                DestinationTableVar.INIT();
                  DestinationTableVar."Entry No." := SourceTableVar."Entry No.";
                DestinationTableVar.Amount := SourceTableVar.Amount;
                DestinationTableVar."Amount (LCY)" := SourceTableVar."Amount (LCY)";
                 DestinationTableVar."Bank Account No." := SourceTableVar."Bank Account No.";
                 DestinationTableVar."Bal. Account Type" := SourceTableVar."Bal. Account Type";
                DestinationTableVar."Statement No.":=SourceTableVar."Statement No.";
                 DestinationTableVar."Statement Status":=SourceTableVar."Statement Status";
                 DestinationTableVar."Statement Line No.":=SourceTableVar."Statement Line No.";
                DestinationTableVar."Transaction No.":=SourceTableVar."Transaction No.";
                DestinationTableVar."User ID" := SourceTableVar."User ID";
                DestinationTableVar."Bank Acc. Posting Group" := SourceTableVar."Bank Acc. Posting Group";
                DestinationTableVar."Check Ledger Entries" := SourceTableVar."Check Ledger Entries";
                DestinationTableVar."Closed at Date" := SourceTableVar."Closed at Date";
                DestinationTableVar."Closed by Entry No." := SourceTableVar."Closed by Entry No.";
                 DestinationTableVar."Credit Amount" := SourceTableVar."Credit Amount";
                 DestinationTableVar."Credit Amount (LCY)" := SourceTableVar."Credit Amount";
                DestinationTableVar."Currency Code" := SourceTableVar."Currency Code";
                DestinationTableVar."Debit Amount" := SourceTableVar."Debit Amount";
                DestinationTableVar."Debit Amount (LCY)" := SourceTableVar."Debit Amount (LCY)";
                DestinationTableVar.Description := SourceTableVar.Description;
                 DestinationTableVar."Document Date" := SourceTableVar."Document Date";
                DestinationTableVar."Document No." := SourceTableVar."Document No.";
                 DestinationTableVar."Document Type" := SourceTableVar."Document Type";
                 DestinationTableVar."External Document No." := SourceTableVar."External Document No.";
                 DestinationTableVar."Global Dimension 1 Code" := SourceTableVar."Global Dimension 1 Code";
                 DestinationTableVar."Global Dimension 2 Code" := SourceTableVar."Global Dimension 2 Code";
                DestinationTableVar."Journal Batch Name" := SourceTableVar."Journal Batch Name";
                DestinationTableVar."Journal Templ. Name" := SourceTableVar."Journal Templ. Name";
                 DestinationTableVar.Open := SourceTableVar.Open;
                DestinationTableVar."Our Contact Code" := SourceTableVar."Our Contact Code";
                DestinationTableVar.Positive := SourceTableVar.Positive;
                 DestinationTableVar."Posting Date" := SourceTableVar."Posting Date";
                 DestinationTableVar."Reason Code" := SourceTableVar."Reason Code";
                 DestinationTableVar."Remaining Amount" := SourceTableVar."Remaining Amount";
                 DestinationTableVar.Reversed := SourceTableVar.Reversed;
                DestinationTableVar."Reversed by Entry No." := SourceTableVar."Reversed by Entry No.";
                DestinationTableVar."Reversed Entry No." := SourceTableVar."Reversed Entry No.";
                if SourceTableVar."Level-03_FINAL Code"<> '' then begin
                DestinationTableVar."Level-03_FINAL Code":= SourceTableVar."Level-03_FINAL Code";
                end
                else begin
                    DestinationTableVar."Level-03_Code" := '';
                end;

                DestinationTableVar.INSERT();
            UNTIL SourceTableVar.NEXT() = 0;
                 END
               
    else begin
            DestinationTableVar.SETRANGE("Entry No.", SourceTableVar."Entry No.");
            IF DestinationTableVar.FINDSET() THEN BEGIN
                  repeat
                  DestinationTableVar."Statement Status" := SourceTableVar."Statement Status";
                  DestinationTableVar."Statement Line No." := SourceTableVar."Statement Line No.";
                  DestinationTableVar."Statement No.":= SourceTableVar."Statement No.";
               
                  DestinationTableVar.Modify();
                  until SourceTableVar.Next()=0;
                 
                 
    END;
    end;
    end;
}
codeunit 90127 BankAccountLedgerEntryCustom
{
    VAR
        SourceTableVar: Record "Bank Account Ledger Entry";
        DestinationTableVar: Record BALTable;
       

    trigger OnRun()
    BEGIN

        SourceTableVar.RESET;
        SourceTableVar.SetRange("Entry No.");
        SourceTableVar.FindLast();
       
        DestinationTableVar.SetRange("Entry No.", SourceTableVar."Entry No.");
       
        IF not
        DestinationTableVar.FINDSET() THEN BEGIN
            REPEAT
                DestinationTableVar.INIT();
                  DestinationTableVar."Entry No." := SourceTableVar."Entry No.";
                DestinationTableVar.Amount := SourceTableVar.Amount;
                DestinationTableVar."Amount (LCY)" := SourceTableVar."Amount (LCY)";
                 DestinationTableVar."Bank Account No." := SourceTableVar."Bank Account No.";
                 DestinationTableVar."Bal. Account Type" := SourceTableVar."Bal. Account Type";
                DestinationTableVar."Statement No.":=SourceTableVar."Statement No.";
                 DestinationTableVar."Statement Status":=SourceTableVar."Statement Status";
                 DestinationTableVar."Statement Line No.":=SourceTableVar."Statement Line No.";
                DestinationTableVar."Transaction No.":=SourceTableVar."Transaction No.";
                DestinationTableVar."User ID" := SourceTableVar."User ID";
                DestinationTableVar."Bank Acc. Posting Group" := SourceTableVar."Bank Acc. Posting Group";
                DestinationTableVar."Check Ledger Entries" := SourceTableVar."Check Ledger Entries";
                DestinationTableVar."Closed at Date" := SourceTableVar."Closed at Date";
                DestinationTableVar."Closed by Entry No." := SourceTableVar."Closed by Entry No.";
                 DestinationTableVar."Credit Amount" := SourceTableVar."Credit Amount";
                 DestinationTableVar."Credit Amount (LCY)" := SourceTableVar."Credit Amount";
                DestinationTableVar."Currency Code" := SourceTableVar."Currency Code";
                DestinationTableVar."Debit Amount" := SourceTableVar."Debit Amount";
                DestinationTableVar."Debit Amount (LCY)" := SourceTableVar."Debit Amount (LCY)";
                DestinationTableVar.Description := SourceTableVar.Description;
                 DestinationTableVar."Document Date" := SourceTableVar."Document Date";
                DestinationTableVar."Document No." := SourceTableVar."Document No.";
                 DestinationTableVar."Document Type" := SourceTableVar."Document Type";
                 DestinationTableVar."External Document No." := SourceTableVar."External Document No.";
                 DestinationTableVar."Global Dimension 1 Code" := SourceTableVar."Global Dimension 1 Code";
                 DestinationTableVar."Global Dimension 2 Code" := SourceTableVar."Global Dimension 2 Code";
                DestinationTableVar."Journal Batch Name" := SourceTableVar."Journal Batch Name";
                DestinationTableVar."Journal Templ. Name" := SourceTableVar."Journal Templ. Name";
                 DestinationTableVar.Open := SourceTableVar.Open;
                DestinationTableVar."Our Contact Code" := SourceTableVar."Our Contact Code";
                DestinationTableVar.Positive := SourceTableVar.Positive;
                 DestinationTableVar."Posting Date" := SourceTableVar."Posting Date";
                 DestinationTableVar."Reason Code" := SourceTableVar."Reason Code";
                 DestinationTableVar."Remaining Amount" := SourceTableVar."Remaining Amount";
                 DestinationTableVar.Reversed := SourceTableVar.Reversed;
                DestinationTableVar."Reversed by Entry No." := SourceTableVar."Reversed by Entry No.";
                DestinationTableVar."Reversed Entry No." := SourceTableVar."Reversed Entry No.";
                if SourceTableVar."Level-03_FINAL Code"<> '' then begin
                DestinationTableVar."Level-03_FINAL Code":= SourceTableVar."Level-03_FINAL Code";
                end
                else begin
                    DestinationTableVar."Level-03_Code" := '';
                end;

                DestinationTableVar.INSERT();
            UNTIL SourceTableVar.NEXT() = 0;
                 END
               
    else begin
            DestinationTableVar.SETRANGE("Entry No.", SourceTableVar."Entry No.");
            IF DestinationTableVar.FINDSET() THEN BEGIN
                  repeat
                  DestinationTableVar."Statement Status" := SourceTableVar."Statement Status";
                  DestinationTableVar."Statement Line No." := SourceTableVar."Statement Line No.";
                  DestinationTableVar."Statement No.":= SourceTableVar."Statement No.";
               
                  DestinationTableVar.Modify();
                  until SourceTableVar.Next()=0;
                 
                 
    END;
    end;
    end;
}

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 739 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 462 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 406 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans