Skip to main content

Notifications

Community site session details

Community site session details

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

Inserting the Record in the table from another table.

(1) ShareShare
ReportReport
Posted on by 2,211 Moderator

So I have a table and I want to insert and remove the records from another table based on the condition.

    trigger OnOpenPage()
    begin
        insertData();
        // Rec.Reset();
        // if (Rec.FindLast() = true) then
        //     exit
        // else
        //     insertData();
    end;
    
    local procedure insertData()
    var
        uerBatchTable: Record uerDistributionBatchTable;
    begin
        uerBatchTable.Reset();
        uerBatchTable.FindSet();
        repeat begin
            if (uerBatchTable.Stop = false) then begin
                Rec.Init();
                Rec.RowNo := Rec.RowNo   1;
                Rec.uerDistributionPoolBatchID := uerBatchTable.uerDistributionPoolBatchID;
                Rec.uerDistributionPoolID := uerBatchTable.uerDistributionPoolID;
                Rec.uerDistributionDate := uerBatchTable.uerDistributionDate;
                Rec.uerDescription := uerBatchTable.uerDescription;
                Rec.uerAmountToAllocate := 0;
                Rec.uerOrigAmountToAllocate := uerBatchTable.uerDistributionAmt;
                Rec.uerPreviousAmountToAllocate := 0;
                Rec.uerAmountNotDistributed := (Rec.uerOrigAmountToAllocate - 0);
                Rec.Insert(true);
            end;
        end;
        until uerBatchTable.Next() = 0;

The first time when I open the page it inserts the records after re-loading again or modifying the condition it gives an error.

pastedimage1666785677017v1.png

Kindly help.

Regards

  • Suggested answer
    DAnny3211 Profile Picture
    9,274 Moderator on at
    RE: Inserting the Record in the table from another table.

    Hi

    my counter would work if your page was temporary:

    so either set the page property TEMPORARY=TRUE

    o

    check which row line is the last one you inserted in the table:

    rec.findlast;

    counter:=Rec.RowNo;

    if (uerBatchTable.Stop = false) then begin

                  counter += 1;

                  Rec.Init();

                  Rec.RowNo := counter

    DAniele

  • Suggested answer
    YUN ZHU Profile Picture
    79,459 Super User 2025 Season 1 on at
    RE: Inserting the Record in the table from another table.

    Hi, if you don't use a temporary table, I think you should add a condition. You must first determine whether this record already exists in your table. If it does not exist, insert it, and skip it if it exists.

    Hope this helps as well

    Thanks.

    ZHU

  • Suggested answer
    Amit_Sharma Profile Picture
    2,545 on at
    RE: Inserting the Record in the table from another table.

    Hi,

    Use Variable instead of REC and then find the last entry no and then increment that last entry number and then insert the recod.

    Regards

    Amit Sharma

    www.erpconsultors.com

  • Govinda Kumar Profile Picture
    2,211 Moderator on at
    RE: Inserting the Record in the table from another table.

    Hey Daniele Incalza,

    Thank you for replying...

    No, my table is not TmpTable and your separate variable for count is not working. As I have tried both ways..

    OnOpenPage trigger first emptying the table and then inserting the data works fine but I want to solve it with the condition.

    Regards.

  • Suggested answer
    DAnny3211 Profile Picture
    9,274 Moderator on at
    RE: Inserting the Record in the table from another table.

    Ciao

    l'errore è il seguente;

    quando fai la INIT del Rec, la tua Rec.RowNo viene resettata a 0. e quindi viene inserita sempre 1.

    provate così, assicurandovi che la PAge sia sempre Temporary=TRUE

       trigger OnOpenPage()

       begin

           insertData();

           // Rec.Reset();

           // if (Rec.FindLast() = true) then

           //     exit

           // else

           //     insertData();

       end;

       local procedure insertData()

       var

           uerBatchTable: Record uerDistributionBatchTable;

           counter: integer;

       begin

           uerBatchTable.Reset();

           uerBatchTable.FindSet();

           repeat begin

               if (uerBatchTable.Stop = false) then begin

                   counter += 1;

                   Rec.Init();

                   Rec.RowNo := counter;

                   Rec.uerDistributionPoolBatchID := uerBatchTable.uerDistributionPoolBatchID;

                   Rec.uerDistributionPoolID := uerBatchTable.uerDistributionPoolID;

                   Rec.uerDistributionDate := uerBatchTable.uerDistributionDate;

                   Rec.uerDescription := uerBatchTable.uerDescription;

                   Rec.uerAmountToAllocate := 0;

                   Rec.uerOrigAmountToAllocate := uerBatchTable.uerDistributionAmt;

                   Rec.uerPreviousAmountToAllocate := 0;

                   Rec.uerAmountNotDistributed := (Rec.uerOrigAmountToAllocate - 0);

                   Rec.Insert(true);

               end;

           end;

           until uerBatchTable.Next() = 0;

    BYe

    DAniele

    check my answer if it solves your problem

  • Suggested answer
    DAnny3211 Profile Picture
    9,274 Moderator on at
    RE: Inserting the Record in the table from another table.

    HI

    the page is Temporary=YES?

    Verify it

    check my answer if it solves your problem

    DAniele

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,289 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,068 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans