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

Notifications

Announcements

No record found.

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,304 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

I have the same question (0)
  • Suggested answer
    DAnny3211 Profile Picture
    11,397 on at

    HI

    the page is Temporary=YES?

    Verify it

    check my answer if it solves your problem

    DAniele

  • Suggested answer
    DAnny3211 Profile Picture
    11,397 on at

    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

  • Govinda Kumar Profile Picture
    2,304 Moderator on at

    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
    Amit Profile Picture
    2,559 on at

    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

  • Suggested answer
    YUN ZHU Profile Picture
    95,741 Super User 2025 Season 2 on at

    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
    DAnny3211 Profile Picture
    11,397 on at

    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

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 2,066

#2
YUN ZHU Profile Picture

YUN ZHU 658 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 595

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans