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 234
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;
}
I have the same question (0)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,055 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,063 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 1,014 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans