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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

This code is not working to copy whole data from bank ledger on basis of entry no. to custom table

(0) ShareShare
ReportReport
Posted on by 234
codeunit 50127 BankAccountLedgerEntryCustom
{
    VAR
        SourceTableVar: Record /Bank Account Ledger Entry/;
        DestinationTableVar: Record BALTable;
 
        BankStatementLine: Record /Bank Account Statement Line/;


 
    trigger OnRun()
    begin
        copytobankledger();
       // copyfrombankledger();
    end;
 
    procedure copytobankledger()
    begin
        DestinationTableVar.RESET();
        SourceTableVar.Reset();
        if SourceTableVar.Findset() then
       repeat
          DestinationTableVar.SetRange(/Entry No./, SourceTableVar./Entry No./);
          IF DestinationTableVar.FIND() THEN begin
           
            DestinationTableVar./Statement Status/ := SourceTableVar./Statement Status/;
                DestinationTableVar./Statement Line No./ := SourceTableVar./Statement Line No./;
                DestinationTableVar./Statement No./ := SourceTableVar./Statement No./;
 
                DestinationTableVar.MODIFY(true);
             
                end
            ELSE BEGIN
              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./;
                DestinationTableVar.INSERT(true) ;
                 end;
   
           
        UNTIL SourceTableVar.NEXT() = 0;
    end;
   
}    
   
I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    61,218 Super User 2026 Season 1 on at
    Please try
     
            DestinationTableVar.RESET();
            SourceTableVar.Reset();
           if SourceTableVar.Findset() then 
           repeat 
              DestinationTableVar.SetRange("Entry No.", SourceTableVar."Entry No.");
              IF DestinationTableVar.FIND() THEN begin
                //your modify code here
              end else begin
                //your insert code here
              end; 
           until SourceTableVar.next() = 0;
  • Pragya752 Profile Picture
    234 on at
    I tried the below code but after running once and copying all data via job queue ,it gave me this error

     
    This is the code that i ran
     
    codeunit 50127 BankAccountLedgerEntryCustom
    {
        VAR
            SourceTableVar: Record "Bank Account Ledger Entry";
            DestinationTableVar: Record BALTable;
     
            BankStatementLine: Record "Bank Account Statement Line";


     
        trigger OnRun()
        begin
            copytobankledger();
           // copyfrombankledger();
        end;
     
        procedure copytobankledger()
        begin
            DestinationTableVar.RESET();
            SourceTableVar.Reset();
            if SourceTableVar.Findset() then
           repeat
              DestinationTableVar.SetRange("Entry No.", SourceTableVar."Entry No.");
              IF DestinationTableVar.FIND() THEN begin
               
                DestinationTableVar."Statement Status" := SourceTableVar."Statement Status";
                    DestinationTableVar."Statement Line No." := SourceTableVar."Statement Line No.";
                    DestinationTableVar."Statement No." := SourceTableVar."Statement No.";
     
                    DestinationTableVar.MODIFY(true);
                 
                    end
                ELSE BEGIN
                  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.";
                    DestinationTableVar.INSERT(true) ;
                     end;
       
               
            UNTIL SourceTableVar.NEXT() = 0;
        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 Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,028 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,366 Super User 2026 Season 1

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 1,175 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans