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...
Answered

To copy whole data of a table from one table to another through a job queue entry

(0) ShareShare
ReportReport
Posted on by 236

I have made a custom table to copy whole data which is already posted in BANK ACCOUNT LEDGER ENTRY table .I am able to do it for once via job queue code that I have written but for new Records in bank ledger entries it is not working. Also,I have 1 field whixh is directly coming from GENERAL JOURNAL  line but for that I have used same field Id.

this is the codeunit that i have used

codeunit 90127 BankAccountLedgerEntryCustom
{
    VAR
        SourceTableVar: Record "Bank Account Ledger Entry";
        DestinationTableVar: Record BALTable;

    trigger OnRun()
    BEGIN

        SourceTableVar.RESET;
        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.INSERT();
            UNTIL SourceTableVar.NEXT = 0;
                 END
                 else
                 begin
                  DestinationTableVar."Statement Status" := SourceTableVar."Statement Status";
                  DestinationTableVar."Statement Line No." := SourceTableVar."Statement Line No.";
                  DestinationTableVar."Statement No.":= SourceTableVar."Statement No.";
                 end;
    END;
}
  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    I assume what you are trying to achieve here is to find the last entry in the source table with this code:

    SourceTableVar.RESET;

           DestinationTableVar.SetRange("Entry No.", SourceTableVar."Entry No.");

    So you should try to add the findlast line and see if that helps you.

    The problem I think is that the sourcetable does not hold a record when you try to get the Entry No. in your setrange statement,

    SourceTableVar.RESET;

    SourceTable.FindLast();

           DestinationTableVar.SetRange("Entry No.", SourceTableVar."Entry No.");

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Hi,

    You can try below code

    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.INSERT();
                UNTIL SourceTableVar.NEXT = 0;
                     END
                     else
                     begin
                      DestinationTableVar."Statement Status" := SourceTableVar."Statement Status";
                      DestinationTableVar."Statement Line No." := SourceTableVar."Statement Line No.";
                      DestinationTableVar."Statement No.":= SourceTableVar."Statement No.";
                      DestinationTableVar.modify;
                      
                     end;
        END;
    }

  • Suggested answer
    YUN ZHU Profile Picture
    104,123 Super User 2026 Season 2 on at

    Hi, it feels like a trigger problem. It is recommended that you put this code in the OnInsert of the table. If it is placed in the OnInsertRecord of the Page, it will only run on that page.

    Hope this can give you some hints.

    Thanks.

    ZHU

  • Pragya752 Profile Picture
    236 on at

    It worked for me but when i am posting data fro m General Journal in which I have added some fields.While posting it,those fields are not coming in gen. journal table and therefore by assigning same field id i am not able to show them in mt custom table as well.What should i do about it.

  • Pragya752 Profile Picture
    236 on at

    if entry no. is found in destination table then will this code only update the following fields?

    DestinationTableVar."Statement Status" := SourceTableVar."Statement Status";

                     DestinationTableVar."Statement Line No." := SourceTableVar."Statement Line No.";

                     DestinationTableVar."Statement No.":= SourceTableVar."Statement No.";

                     DestinationTableVar.modify;

  • Suggested answer
    Govinda Kumar Profile Picture
    2,310 Moderator on at

    yeah, a.c to your code.. if entry no. is not found in the destination table then it will insert the record in your source table.. if entry no. is found in the destination table then it will only update those fields..

  • Pragya752 Profile Picture
    236 on at

    hi this code that you provided is not working for entries which are already present and needed to be updated for fields Statement no,line etc.

  • Verified answer
    Govinda Kumar Profile Picture
    2,310 Moderator on at

    Try this code

    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 (DestinationTableVar.FindSet()) then begin
                DestinationTableVar."Statement Status" := SourceTableVar."Statement Status";
                DestinationTableVar."Statement Line No." := SourceTableVar."Statement Line No.";
                DestinationTableVar."Statement No." := SourceTableVar."Statement No.";
                DestinationTableVar.Modify;
            end
            else begin
                DestinationTableVar.INIT();
                DestinationTableVar."Entry No." := SourceTableVar."Entry No.";
                DestinationTableVar.Amount := SourceTableVar.Amount;
                DestinationTableVar."Amount (LCY)" := SourceTableVar."Amount (LCY)";
                DestinationTableVar.INSERT();
            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

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 631 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 409 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 222 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans