web
You’re offline. This is a read only version of the page.
close
Skip to main content
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 234

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;
}
I have the same question (0)
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 Moderator on at
    RE: To copy whole data of a table from one table to another through a job queue entry

    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,698 Moderator on at
    RE: To copy whole data of a table from one table to another through a job queue entry

    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
    95,307 Super User 2025 Season 2 on at
    RE: To copy whole data of a table from one table to another through a job queue entry

    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
    234 on at
    RE: To copy whole data of a table from one table to another through a job queue entry

    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
    234 on at
    RE: To copy whole data of a table from one table to another through a job queue entry

    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,304 Moderator on at
    RE: To copy whole data of a table from one table to another through a job queue entry

    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
    234 on at
    RE: To copy whole data of a table from one table to another through a job queue entry

    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,304 Moderator on at
    RE: To copy whole data of a table from one table to another through a job queue entry

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,377

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,696 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,512 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans