Skip to main content

Notifications

Announcements

No record found.

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 210

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;
}
  • Verified answer
    Govinda Kumar Profile Picture
    Govinda Kumar 2,198 Super User 2024 Season 1 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;
    }

  • Pragya752 Profile Picture
    Pragya752 210 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.

  • Suggested answer
    Govinda Kumar Profile Picture
    Govinda Kumar 2,198 Super User 2024 Season 1 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
    Pragya752 210 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;

  • Pragya752 Profile Picture
    Pragya752 210 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.

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 75,561 Super User 2024 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

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,081 Super User 2024 Season 1 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
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 993 Super User 2024 Season 1 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.");

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,622 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,354 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans